39 lines
991 B
Python
39 lines
991 B
Python
import json
|
|
from http import HTTPStatus
|
|
|
|
from aws_lambda_powertools.event_handler import Response
|
|
from aws_lambda_powertools.event_handler.api_gateway import Router
|
|
from elasticsearch import Elasticsearch
|
|
|
|
import elastic
|
|
from http_models import SearchResponse
|
|
from models import Course
|
|
from settings import COURSE_TABLE, ELASTIC_CONN
|
|
|
|
router = Router()
|
|
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
|
|
|
|
|
@router.get('/', compress=True)
|
|
def get_courses() -> SearchResponse:
|
|
event = router.current_event
|
|
query = event.get_query_string_value('query', '{}')
|
|
page_size = event.get_query_string_value('page_size', '25')
|
|
|
|
return elastic.search( # type: ignore
|
|
index=COURSE_TABLE,
|
|
page_size=int(page_size),
|
|
query=json.loads(query),
|
|
elastic_client=elastic_client,
|
|
)
|
|
|
|
|
|
@router.post('/', compress=True)
|
|
def post_course(payload: Course):
|
|
return Response(status_code=HTTPStatus.CREATED)
|
|
|
|
|
|
@router.get('/<id>')
|
|
def get_course(id: str):
|
|
return {}
|