|
30 | 30 | CommonDeps = Annotated[dict[str, Any], Depends(common_query_parameters)] |
31 | 31 |
|
32 | 32 |
|
33 | | -@router.delete( |
34 | | - "/v1/customers/{customer_id}", |
35 | | - responses={ |
36 | | - 204: {"description": "No Content."}, |
37 | | - 400: {"model": ErrorMessage, "description": "Bad Request."}, |
38 | | - 401: {"model": ErrorMessage, "description": "Unauthorized."}, |
39 | | - 403: {"model": ErrorMessage, "description": "Forbidden."}, |
40 | | - 404: {"model": ErrorMessage, "description": "Not Found."}, |
41 | | - 405: {"model": ErrorMessage, "description": "Method Not Allowed."}, |
42 | | - 422: {"model": ErrorMessage, "description": "Unprocessable Entity."}, |
43 | | - 500: {"model": ErrorMessage, "description": "Internal Server Error."}, |
44 | | - 502: {"model": ErrorMessage, "description": "Bad Gateway."}, |
45 | | - 503: {"model": ErrorMessage, "description": "Service Unavailable."}, |
46 | | - 504: {"model": ErrorMessage, "description": "Gateway Timeout."}, |
47 | | - }, |
48 | | - tags=["Customers"], |
49 | | - summary="Delete specific customer.", |
50 | | - response_model=None, |
51 | | -) |
52 | | -async def delete_customer_id( |
53 | | - customer_id: Annotated[UUID4, Path(description="Id of a specific customer.")], |
54 | | - http_request_info: CommonDeps, |
55 | | - db_connection: Annotated[Session, Depends(get_db_session)], |
56 | | -) -> Response: |
57 | | - """Delete the information of the customer with the matching Id.""" |
58 | | - logger.info("Entering...") |
59 | | - logger.debug("Deleting customer with id %s", customer_id) |
60 | | - try: |
61 | | - CustomerApplicationService.delete_customer(db_connection, customer_id) |
62 | | - logger.debug("Customer with id %s deleted", customer_id) |
63 | | - except ElementNotFoundError as error: |
64 | | - logger.error("Customer with id %s not found", customer_id) # noqa: TRY400 |
65 | | - raise HTTP404NotFoundError from error |
66 | | - except Exception as error: |
67 | | - logger.exception("Error deleting customer with id %s", customer_id) |
68 | | - raise HTTP500InternalServerError from error |
69 | | - logger.info("Exiting...") |
70 | | - return Response(status_code=status.HTTP_204_NO_CONTENT, headers=http_request_info) |
71 | | - |
72 | | - |
73 | 33 | @router.get( |
74 | 34 | "/v1/customers", |
75 | 35 | responses={ |
@@ -150,49 +110,6 @@ async def get_customers( |
150 | 110 | ) |
151 | 111 |
|
152 | 112 |
|
153 | | -@router.get( |
154 | | - "/v1/customers/{customer_id}", |
155 | | - responses={ |
156 | | - 200: {"model": CustomerDetailResponse, "description": "OK."}, |
157 | | - 401: {"model": ErrorMessage, "description": "Unauthorized."}, |
158 | | - 403: {"model": ErrorMessage, "description": "Forbidden."}, |
159 | | - 404: {"model": ErrorMessage, "description": "Not Found."}, |
160 | | - 422: {"model": ErrorMessage, "description": "Unprocessable Entity."}, |
161 | | - 423: {"model": ErrorMessage, "description": "Locked."}, |
162 | | - 500: {"model": ErrorMessage, "description": "Internal Server Error."}, |
163 | | - 501: {"model": ErrorMessage, "description": "Not Implemented."}, |
164 | | - 502: {"model": ErrorMessage, "description": "Bad Gateway."}, |
165 | | - 503: {"model": ErrorMessage, "description": "Service Unavailable."}, |
166 | | - 504: {"model": ErrorMessage, "description": "Gateway Timeout."}, |
167 | | - }, |
168 | | - tags=["Customers"], |
169 | | - summary="Customer information.", |
170 | | - response_model_by_alias=True, |
171 | | - response_model=CustomerDetailResponse, |
172 | | -) |
173 | | -async def get_customer_id( |
174 | | - http_request_info: CommonDeps, |
175 | | - db_connection: Annotated[Session, Depends(get_db_session)], |
176 | | - customer_id: Annotated[UUID4, Path(description="Id of a specific customer.")], |
177 | | -) -> JSONResponse: |
178 | | - """Retrieve the information of the customer with the matching code.""" |
179 | | - logger.info("Entering...") |
180 | | - logger.debug("Getting customer with id %s", customer_id) |
181 | | - try: |
182 | | - api_data = CustomerApplicationService.get_customer_id(db_connection, customer_id) |
183 | | - logger.debug("Customer with id %s retrieved", customer_id) |
184 | | - except ElementNotFoundError as error: |
185 | | - logger.error("Customer with id %s not found", customer_id) # noqa: TRY400 |
186 | | - raise HTTP404NotFoundError from error |
187 | | - except Exception as error: |
188 | | - logger.exception("Error getting customer with id %s", customer_id) |
189 | | - raise HTTP500InternalServerError from error |
190 | | - logger.info("Exiting...") |
191 | | - return JSONResponse( |
192 | | - content=api_data.model_dump(), status_code=status.HTTP_200_OK, headers=http_request_info |
193 | | - ) |
194 | | - |
195 | | - |
196 | 113 | @router.post( |
197 | 114 | "/v1/customers", |
198 | 115 | responses={ |
@@ -278,6 +195,89 @@ async def put_customers_customer_id( |
278 | 195 | return Response(status_code=status.HTTP_204_NO_CONTENT, headers=http_request_info) |
279 | 196 |
|
280 | 197 |
|
| 198 | +@router.delete( |
| 199 | + "/v1/customers/{customer_id}", |
| 200 | + responses={ |
| 201 | + 204: {"description": "No Content."}, |
| 202 | + 400: {"model": ErrorMessage, "description": "Bad Request."}, |
| 203 | + 401: {"model": ErrorMessage, "description": "Unauthorized."}, |
| 204 | + 403: {"model": ErrorMessage, "description": "Forbidden."}, |
| 205 | + 404: {"model": ErrorMessage, "description": "Not Found."}, |
| 206 | + 405: {"model": ErrorMessage, "description": "Method Not Allowed."}, |
| 207 | + 422: {"model": ErrorMessage, "description": "Unprocessable Entity."}, |
| 208 | + 500: {"model": ErrorMessage, "description": "Internal Server Error."}, |
| 209 | + 502: {"model": ErrorMessage, "description": "Bad Gateway."}, |
| 210 | + 503: {"model": ErrorMessage, "description": "Service Unavailable."}, |
| 211 | + 504: {"model": ErrorMessage, "description": "Gateway Timeout."}, |
| 212 | + }, |
| 213 | + tags=["Customers"], |
| 214 | + summary="Delete specific customer.", |
| 215 | + response_model=None, |
| 216 | +) |
| 217 | +async def delete_customer_id( |
| 218 | + customer_id: Annotated[UUID4, Path(description="Id of a specific customer.")], |
| 219 | + http_request_info: CommonDeps, |
| 220 | + db_connection: Annotated[Session, Depends(get_db_session)], |
| 221 | +) -> Response: |
| 222 | + """Delete the information of the customer with the matching Id.""" |
| 223 | + logger.info("Entering...") |
| 224 | + logger.debug("Deleting customer with id %s", customer_id) |
| 225 | + try: |
| 226 | + CustomerApplicationService.delete_customer(db_connection, customer_id) |
| 227 | + logger.debug("Customer with id %s deleted", customer_id) |
| 228 | + except ElementNotFoundError as error: |
| 229 | + logger.error("Customer with id %s not found", customer_id) # noqa: TRY400 |
| 230 | + raise HTTP404NotFoundError from error |
| 231 | + except Exception as error: |
| 232 | + logger.exception("Error deleting customer with id %s", customer_id) |
| 233 | + raise HTTP500InternalServerError from error |
| 234 | + logger.info("Exiting...") |
| 235 | + return Response(status_code=status.HTTP_204_NO_CONTENT, headers=http_request_info) |
| 236 | + |
| 237 | + |
| 238 | +@router.get( |
| 239 | + "/v1/customers/{customer_id}", |
| 240 | + responses={ |
| 241 | + 200: {"model": CustomerDetailResponse, "description": "OK."}, |
| 242 | + 401: {"model": ErrorMessage, "description": "Unauthorized."}, |
| 243 | + 403: {"model": ErrorMessage, "description": "Forbidden."}, |
| 244 | + 404: {"model": ErrorMessage, "description": "Not Found."}, |
| 245 | + 422: {"model": ErrorMessage, "description": "Unprocessable Entity."}, |
| 246 | + 423: {"model": ErrorMessage, "description": "Locked."}, |
| 247 | + 500: {"model": ErrorMessage, "description": "Internal Server Error."}, |
| 248 | + 501: {"model": ErrorMessage, "description": "Not Implemented."}, |
| 249 | + 502: {"model": ErrorMessage, "description": "Bad Gateway."}, |
| 250 | + 503: {"model": ErrorMessage, "description": "Service Unavailable."}, |
| 251 | + 504: {"model": ErrorMessage, "description": "Gateway Timeout."}, |
| 252 | + }, |
| 253 | + tags=["Customers"], |
| 254 | + summary="Customer information.", |
| 255 | + response_model_by_alias=True, |
| 256 | + response_model=CustomerDetailResponse, |
| 257 | +) |
| 258 | +async def get_customer_id( |
| 259 | + http_request_info: CommonDeps, |
| 260 | + db_connection: Annotated[Session, Depends(get_db_session)], |
| 261 | + customer_id: Annotated[UUID4, Path(description="Id of a specific customer.")], |
| 262 | +) -> JSONResponse: |
| 263 | + """Retrieve the information of the customer with the matching code.""" |
| 264 | + logger.info("Entering...") |
| 265 | + logger.debug("Getting customer with id %s", customer_id) |
| 266 | + try: |
| 267 | + api_data = CustomerApplicationService.get_customer_id(db_connection, customer_id) |
| 268 | + logger.debug("Customer with id %s retrieved", customer_id) |
| 269 | + except ElementNotFoundError as error: |
| 270 | + logger.error("Customer with id %s not found", customer_id) # noqa: TRY400 |
| 271 | + raise HTTP404NotFoundError from error |
| 272 | + except Exception as error: |
| 273 | + logger.exception("Error getting customer with id %s", customer_id) |
| 274 | + raise HTTP500InternalServerError from error |
| 275 | + logger.info("Exiting...") |
| 276 | + return JSONResponse( |
| 277 | + content=api_data.model_dump(), status_code=status.HTTP_200_OK, headers=http_request_info |
| 278 | + ) |
| 279 | + |
| 280 | + |
281 | 281 | @router.post( |
282 | 282 | "/v1/customers/{customer_id}/addresses", |
283 | 283 | responses={ |
|
0 commit comments