mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
refactor(chart): Fixed tabulation and code duplicates
This commit is contained in:
parent
85acbbb16c
commit
ded9abc816
2 changed files with 31 additions and 29 deletions
|
@ -13,7 +13,7 @@ async def get_chart(
|
|||
conv_currency: str = None,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
):
|
||||
):
|
||||
|
||||
if not from_currency or not conv_currency:
|
||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
|
@ -21,6 +21,7 @@ async def get_chart(
|
|||
'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 {
|
||||
|
@ -30,5 +31,4 @@ async def get_chart(
|
|||
|
||||
|
||||
chart = await create_chart(from_currency, conv_currency, start_date, end_date)
|
||||
|
||||
return await prepare_chart_response(response, request, chart)
|
|
@ -14,7 +14,7 @@ async def get_chart_period(
|
|||
from_currency: str = None,
|
||||
conv_currency: str = None,
|
||||
period: str = None,
|
||||
):
|
||||
):
|
||||
|
||||
if not from_currency or not conv_currency:
|
||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
|
@ -41,7 +41,8 @@ async def get_chart_period(
|
|||
end_date = datetime.now()
|
||||
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,
|
||||
start_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)
|
||||
|
||||
|
||||
async def prepare_chart_response(response: Response, request: Request, chart_name: str):
|
||||
if not chart_name:
|
||||
response.status_code = status.HTTP_404_NOT_FOUND
|
||||
|
|
Loading…
Add table
Reference in a new issue