diff --git a/db.py b/db.py index 6121c82..573d135 100644 --- a/db.py +++ b/db.py @@ -24,5 +24,8 @@ if __name__ == '__main__': async def initdb(): conn = await connect() await create(conn) + await conn.commit() + + await conn.close() - asyncio.run(initdb) \ No newline at end of file + asyncio.run(initdb()) \ No newline at end of file diff --git a/main.py b/main.py index f039be1..df393bd 100644 --- a/main.py +++ b/main.py @@ -188,4 +188,8 @@ async def login(data: LoginBody, conn: sqlite3.Connection = Depends(get_db)) -> response = JSONResponse(content=jsonable_encoder(person)) response.set_cookie(key='user_id', value=str(person.id)) - return response \ No newline at end of file + return response + +@app.get('/auth/refresh') +async def current_user(user: persons.Person = Depends(cookie_person)) -> persons.Person: + return user \ No newline at end of file diff --git a/meals/db.py b/meals/db.py index 9b3a4ec..aaaefd3 100644 --- a/meals/db.py +++ b/meals/db.py @@ -94,7 +94,7 @@ async def find_meal_by_id(conn, meal_id: int) -> Meal: async def find_meal_by_date(conn, date: datetime) -> Meal: async with conn.execute(f''' SELECT {','.join(Meal.KEYS)} FROM Meal - WHERE date = ? + WHERE meal_date = ? LIMIT 1 ''', (date,)) as cursor: async for row in cursor: @@ -103,7 +103,7 @@ async def find_meal_by_date(conn, date: datetime) -> Meal: async def find_meals_by_date_range(conn, start: datetime, end: datetime) -> List[Meal]: async with conn.execute(f''' SELECT {','.join(Meal.KEYS)} FROM Meal - WHERE date >= ? AND date <= ? + WHERE meal_date >= ? AND meal_date <= ? ''', (start, end)) as cursor: result = [] async for row in cursor: diff --git a/tests.py b/tests.py index 515ee2c..f612469 100644 --- a/tests.py +++ b/tests.py @@ -144,5 +144,11 @@ class TestMeals(unittest.IsolatedAsyncioTestCase): self.assertEqual(meal_by_id.extra_ingredients[0].id, extra_ingredient.id) self.assertEqual(meal_by_id.extra_ingredients[0].line, extra_ingredient.line) + meals_by_date_range = await main.get_meals(meal.meal_date, meal.meal_date, self.conn) + self.assertIsNotNone(meals_by_date_range) + self.assertIsInstance(meals_by_date_range, list, msg=meals_by_date_range.body if hasattr(meals_by_date_range, 'body') else meals_by_date_range) + self.assertEqual(len(meals_by_date_range), 1) + self.assertEqual(meals_by_date_range[0].id, meal.id) + if __name__ == '__main__': unittest.main() \ No newline at end of file