1515router = APIRouter ()
1616
1717
18+ @router .get ("/" , response_model = List [SummarySchema ])
19+ async def read_all_summaries () -> List [SummarySchema ]:
20+ return await crud .get_all ()
21+
22+
23+ @router .get ("/{id}/" , response_model = SummarySchema )
24+ async def read_summary (id : int = Path (..., gt = 0 )) -> SummarySchema :
25+ summary = await crud .get (id )
26+ if not summary :
27+ raise HTTPException (status_code = 404 , detail = "Summary not found" )
28+
29+ return summary
30+
31+
1832@router .post ("/" , response_model = SummaryResponseSchema , status_code = 201 )
1933async def create_summary (
2034 payload : SummaryPayloadSchema , background_tasks : BackgroundTasks
@@ -27,20 +41,17 @@ async def create_summary(
2741 return response_object
2842
2943
30- @router .get ("/{id}/" , response_model = SummarySchema )
31- async def read_summary (id : int = Path (..., gt = 0 )) -> SummarySchema :
32- summary = await crud .get (id )
44+ @router .put ("/{id}/" , response_model = SummarySchema )
45+ async def update_summary (
46+ payload : SummaryUpdatePayloadSchema , id : int = Path (..., gt = 0 )
47+ ) -> SummarySchema :
48+ summary = await crud .put (id , payload )
3349 if not summary :
3450 raise HTTPException (status_code = 404 , detail = "Summary not found" )
3551
3652 return summary
3753
3854
39- @router .get ("/" , response_model = List [SummarySchema ])
40- async def read_all_summaries () -> List [SummarySchema ]:
41- return await crud .get_all ()
42-
43-
4455@router .delete ("/{id}/" , response_model = SummaryResponseSchema )
4556async def delete_summary (id : int = Path (..., gt = 0 )) -> SummaryResponseSchema :
4657 summary = await crud .get (id )
@@ -50,14 +61,3 @@ async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema:
5061 await crud .delete (id )
5162
5263 return summary
53-
54-
55- @router .put ("/{id}/" , response_model = SummarySchema )
56- async def update_summary (
57- payload : SummaryUpdatePayloadSchema , id : int = Path (..., gt = 0 )
58- ) -> SummarySchema :
59- summary = await crud .put (id , payload )
60- if not summary :
61- raise HTTPException (status_code = 404 , detail = "Summary not found" )
62-
63- return summary
0 commit comments