Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/kitchen_mate/src/kitchen_mate/routes/sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
save_user_recipe,
)
from kitchen_mate.schemas import CreateShareResponse, SaveSharedRecipeResponse, SharedRecipeResponse
from kitchen_mate.storage import StorageBackend, get_storage


router = APIRouter()
Expand Down Expand Up @@ -54,7 +55,10 @@ async def delete_share(


@router.get("/shared/{share_token}", response_model=SharedRecipeResponse)
async def get_shared_recipe(share_token: str) -> SharedRecipeResponse:
async def get_shared_recipe(
share_token: str,
storage: Annotated[StorageBackend, Depends(get_storage)],
) -> SharedRecipeResponse:
"""View a shared recipe. No authentication required."""
share = await get_share_by_token(share_token)
if share is None:
Expand All @@ -64,9 +68,13 @@ async def get_shared_recipe(share_token: str) -> SharedRecipeResponse:
if user_recipe is None:
raise HTTPException(status_code=404, detail="Recipe not found")

recipe = user_recipe.recipe
if user_recipe.thumbnail_key:
recipe = recipe.model_copy(update={"image": storage.get_url(user_recipe.thumbnail_key)})

return SharedRecipeResponse(
title=user_recipe.recipe.title,
recipe=user_recipe.recipe,
title=recipe.title,
recipe=recipe,
shared_at=share.created_at.isoformat(),
)

Expand Down
Loading