feat(charts): Changed the name of the status code in the response. If there is no argument, the error is now Kekkai, not FastAPI.

This commit is contained in:
Данил 2024-10-31 20:10:39 +03:00
parent a43230cd9e
commit 38d1ace398

View file

@ -40,11 +40,22 @@ app.middleware('http')(PlausibleAnalytics())
async def get_chart( async def get_chart(
response: Response, response: Response,
request: Request, request: Request,
from_currency: str,
conv_currency: str,
start_date: str,
end_date: str
): ):
from_currency, conv_currency, start_date, end_date = None, None, None, None
if not from_currency or not conv_currency:
response.status_code = status.HTTP_400_BAD_REQUEST
return {
'status': status.HTTP_400_BAD_REQUEST,
'message': 'The from_currency and conv_currency fields are required.',
}
elif not start_date and not end_date:
response.status_code = status.HTTP_400_BAD_REQUEST
return {
'status': status.HTTP_400_BAD_REQUEST,
'message': 'The start_date and end_date fields are required.',
}
chart = await create_chart(from_currency, conv_currency, start_date, end_date) chart = await create_chart(from_currency, conv_currency, start_date, end_date)
@ -56,8 +67,8 @@ async def get_chart(
url_schema = request.url.scheme url_schema = request.url.scheme
return { return {
'status': status.HTTP_400_BAD_REQUEST,
'message': f'{url_schema}://{host}/static/charts/{chart}.png', 'message': f'{url_schema}://{host}/static/charts/{chart}.png',
'status_code': status.HTTP_201_CREATED,
} }
@ -65,11 +76,17 @@ async def get_chart(
async def get_chart_period( async def get_chart_period(
response: Response, response: Response,
request: Request, request: Request,
from_currency: str,
conv_currency: str,
period: str
): ):
from_currency, conv_currency, period = None, None, None
if not from_currency or not conv_currency:
response.status_code = status.HTTP_400_BAD_REQUEST
return {
'status': status.HTTP_400_BAD_REQUEST,
'message': 'The from_currency and conv_currency fields are required.',
}
if period not in ['week', 'month', 'quarter', 'year']: if period not in ['week', 'month', 'quarter', 'year']:
response.status_code = status.HTTP_400_BAD_REQUEST response.status_code = status.HTTP_400_BAD_REQUEST
return {'message': 'Invalid period.', 'status_code': status.HTTP_400_BAD_REQUEST} return {'message': 'Invalid period.', 'status_code': status.HTTP_400_BAD_REQUEST}
@ -102,8 +119,8 @@ async def get_chart_period(
url_schema = request.url.scheme url_schema = request.url.scheme
return { return {
'status': status.HTTP_201_CREATED,
'message': f'{url_schema}://{host}/static/charts/{chart}.png', 'message': f'{url_schema}://{host}/static/charts/{chart}.png',
'status_code': status.HTTP_201_CREATED,
} }