fix meal-image not return on API call

This commit is contained in:
hay-kot 2021-06-04 18:03:34 -08:00
commit 545fbf253e
2 changed files with 23 additions and 22 deletions

View file

@ -45,6 +45,26 @@ def get_today(session: Session = Depends(generate_session), current_user: UserIn
return recipe return recipe
@router.get("/today/image", tags=["Meal Plan"])
def get_todays_image(session: Session = Depends(generate_session), group_name: str = "Home"):
"""
Returns the image for todays meal-plan.
"""
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
recipe = get_todays_meal(session, group_in_db)
if recipe:
recipe_image = recipe.image_dir.joinpath(image.ImageOptions.ORIGINAL_IMAGE)
print(recipe_image)
else:
raise HTTPException(status.HTTP_404_NOT_FOUND)
if recipe_image:
return FileResponse(recipe_image)
else:
raise HTTPException(status.HTTP_404_NOT_FOUND)
@router.get("/{id}", response_model=MealPlanOut) @router.get("/{id}", response_model=MealPlanOut)
def get_meal_plan( def get_meal_plan(
id, id,
@ -106,22 +126,3 @@ def delete_meal_plan(
) )
except Exception: except Exception:
raise HTTPException(status.HTTP_400_BAD_REQUEST) raise HTTPException(status.HTTP_400_BAD_REQUEST)
@router.get("/today/image", tags=["Meal Plan"])
def get_todays_image(session: Session = Depends(generate_session), group_name: str = "Home"):
"""
Returns the image for todays meal-plan.
"""
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
recipe = get_todays_meal(session, group_in_db)
if recipe:
recipe_image = recipe.image_dir.joinpath(image.ImageOptions.ORIGINAL_IMAGE)
else:
raise HTTPException(status.HTTP_404_NOT_FOUND)
if recipe_image:
return FileResponse(recipe_image)
else:
raise HTTPException(status.HTTP_404_NOT_FOUND)

View file

@ -12,9 +12,9 @@ logger = root_logger.get_logger()
@dataclass @dataclass
class ImageOptions: class ImageOptions:
ORIGINAL_IMAGE: str = "original*" ORIGINAL_IMAGE: str = "original.webp"
MINIFIED_IMAGE: str = "min-original*" MINIFIED_IMAGE: str = "min-original.webp"
TINY_IMAGE: str = "tiny-original*" TINY_IMAGE: str = "tiny-original.webp"
IMG_OPTIONS = ImageOptions() IMG_OPTIONS = ImageOptions()