diff --git a/chart/routes/get_chart.py b/chart/routes/get_chart.py index dc2e7b3..e471fd2 100644 --- a/chart/routes/get_chart.py +++ b/chart/routes/get_chart.py @@ -7,28 +7,28 @@ router = APIRouter() @router.get("/api/getChart/", status_code=status.HTTP_201_CREATED) async def get_chart( - response: Response, - request: Request, - from_currency: str = None, - conv_currency: str = None, - start_date: str = None, - end_date: str = None, - ): + response: Response, + request: Request, + from_currency: str = None, + 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 return { - 'status': status.HTTP_400_BAD_REQUEST, - 'message': 'The from_currency and conv_currency fields are required.', - } + '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.', + '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) - - return await prepare_chart_response(response, request, chart) \ No newline at end of file + return await prepare_chart_response(response, request, chart) diff --git a/chart/routes/get_chart_period.py b/chart/routes/get_chart_period.py index 658b2b1..bc975fb 100644 --- a/chart/routes/get_chart_period.py +++ b/chart/routes/get_chart_period.py @@ -9,19 +9,19 @@ router = APIRouter() @router.get("/api/getChart/{period}", status_code=status.HTTP_201_CREATED) async def get_chart_period( - response: Response, - request: Request, - from_currency: str = None, - conv_currency: str = None, - period: str = None, - ): + response: Response, + request: Request, + 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 return { - 'status': status.HTTP_400_BAD_REQUEST, - 'message': 'The from_currency and conv_currency fields are required.', - } + 'status': status.HTTP_400_BAD_REQUEST, + 'message': 'The from_currency and conv_currency fields are required.', + } if period not in ['week', 'month', 'quarter', 'year']: response.status_code = status.HTTP_400_BAD_REQUEST @@ -41,14 +41,16 @@ 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, - conv_currency, - start_date.strftime('%Y-%m-%d'), - end_date.strftime('%Y-%m-%d') - ) + chart = await create_chart( + from_currency, + conv_currency, + start_date.strftime('%Y-%m-%d'), + end_date.strftime('%Y-%m-%d') + ) 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 @@ -60,4 +62,4 @@ async def prepare_chart_response(response: Response, request: Request, chart_nam return { 'status': status.HTTP_201_CREATED, 'message': f'{url_schema}://{host}/static/charts/{chart_name}.png', - } \ No newline at end of file + }