refactor(chart): Fixed tabulation and code duplicates

This commit is contained in:
Данил 2024-12-14 23:36:01 +03:00
parent 85acbbb16c
commit ded9abc816
2 changed files with 31 additions and 29 deletions

View file

@ -13,7 +13,7 @@ async def get_chart(
conv_currency: str = None, conv_currency: str = None,
start_date: str = None, start_date: str = None,
end_date: str = None, end_date: str = None,
): ):
if not from_currency or not conv_currency: if not from_currency or not conv_currency:
response.status_code = status.HTTP_400_BAD_REQUEST response.status_code = status.HTTP_400_BAD_REQUEST
@ -21,6 +21,7 @@ async def get_chart(
'status': status.HTTP_400_BAD_REQUEST, 'status': status.HTTP_400_BAD_REQUEST,
'message': 'The from_currency and conv_currency fields are required.', 'message': 'The from_currency and conv_currency fields are required.',
} }
elif not start_date and not end_date: elif not start_date and not end_date:
response.status_code = status.HTTP_400_BAD_REQUEST response.status_code = status.HTTP_400_BAD_REQUEST
return { return {
@ -30,5 +31,4 @@ async def get_chart(
chart = await create_chart(from_currency, conv_currency, start_date, end_date) chart = await create_chart(from_currency, conv_currency, start_date, end_date)
return await prepare_chart_response(response, request, chart) return await prepare_chart_response(response, request, chart)

View file

@ -14,7 +14,7 @@ async def get_chart_period(
from_currency: str = None, from_currency: str = None,
conv_currency: str = None, conv_currency: str = None,
period: str = None, period: str = None,
): ):
if not from_currency or not conv_currency: if not from_currency or not conv_currency:
response.status_code = status.HTTP_400_BAD_REQUEST response.status_code = status.HTTP_400_BAD_REQUEST
@ -41,7 +41,8 @@ async def get_chart_period(
end_date = datetime.now() end_date = datetime.now()
start_date = end_date + dateutil.relativedelta.relativedelta(months=month, days=days, years=years) start_date = end_date + dateutil.relativedelta.relativedelta(months=month, days=days, years=years)
chart = await create_chart(from_currency, chart = await create_chart(
from_currency,
conv_currency, conv_currency,
start_date.strftime('%Y-%m-%d'), start_date.strftime('%Y-%m-%d'),
end_date.strftime('%Y-%m-%d') end_date.strftime('%Y-%m-%d')
@ -49,6 +50,7 @@ async def get_chart_period(
return await prepare_chart_response(response, request, chart) return await prepare_chart_response(response, request, chart)
async def prepare_chart_response(response: Response, request: Request, chart_name: str): async def prepare_chart_response(response: Response, request: Request, chart_name: str):
if not chart_name: if not chart_name:
response.status_code = status.HTTP_404_NOT_FOUND response.status_code = status.HTTP_404_NOT_FOUND