fix: Condition of no parameters

This commit is contained in:
Данил 2024-11-05 22:32:06 +03:00
parent eab1a0d2fc
commit 7ad43f5a6d

View file

@ -40,8 +40,11 @@ app.middleware('http')(PlausibleAnalytics())
async def get_chart( async def get_chart(
response: Response, response: Response,
request: Request, request: Request,
from_currency: str = None,
conv_currency: str = None,
start_date: str = None,
end_date: str = None,
): ):
from_currency, conv_currency, start_date, end_date = None, None, None, 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
@ -76,10 +79,11 @@ 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 = None,
conv_currency: str = None,
period: str = None,
): ):
from_currency, conv_currency, period = None, None, 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
return { return {
@ -124,7 +128,7 @@ async def get_chart_period(
} }
async def create_chart(from_currency: str, conv_currency: str, start_date: str, end_date: str) -> (str, bool): async def create_chart(from_currency: str, conv_currency: str, start_date: str, end_date: str) -> str:
cur.execute('SELECT date, rate FROM currency WHERE (date BETWEEN %s AND %s) ' cur.execute('SELECT date, rate FROM currency WHERE (date BETWEEN %s AND %s) '
'AND from_currency = %s AND conv_currency = %s ORDER BY date', 'AND from_currency = %s AND conv_currency = %s ORDER BY date',
[ [