mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-23 18:55:15 -05:00
feat: public recipe access (#1610)
* initial public explorer API endpoint * public API endpoint * cleanup recipe page * wip: init explorer page * use public URLs for shared recipes * refactor private share tokens to use shared page
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import admin, app, auth, comments, groups, organizers, parser, recipe, shared, unit_and_foods, users, validators
|
||||
from . import (
|
||||
admin,
|
||||
app,
|
||||
auth,
|
||||
comments,
|
||||
explore,
|
||||
groups,
|
||||
organizers,
|
||||
parser,
|
||||
recipe,
|
||||
shared,
|
||||
unit_and_foods,
|
||||
users,
|
||||
validators,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/api")
|
||||
|
||||
@@ -16,3 +30,4 @@ router.include_router(parser.router)
|
||||
router.include_router(unit_and_foods.router)
|
||||
router.include_router(admin.router)
|
||||
router.include_router(validators.router)
|
||||
router.include_router(explore.router)
|
||||
|
||||
7
mealie/routes/explore/__init__.py
Normal file
7
mealie/routes/explore/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import controller_public_recipes
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
router.include_router(controller_public_recipes.router)
|
||||
25
mealie/routes/explore/controller_public_recipes.py
Normal file
25
mealie/routes/explore/controller_public_recipes.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import UUID4
|
||||
|
||||
from mealie.routes._base import controller
|
||||
from mealie.routes._base.base_controllers import BasePublicController
|
||||
from mealie.schema.recipe import Recipe
|
||||
|
||||
router = APIRouter(prefix="/explore", tags=["Explore: Recipes"])
|
||||
|
||||
|
||||
@controller(router)
|
||||
class PublicRecipesController(BasePublicController):
|
||||
@router.get("/recipes/{group_id}/{recipe_slug}", response_model=Recipe)
|
||||
def get_recipe(self, group_id: UUID4, recipe_slug: str) -> Recipe:
|
||||
group = self.repos.groups.get_one(group_id)
|
||||
|
||||
if not group or group.preferences.private_group:
|
||||
raise HTTPException(404, "group not found")
|
||||
|
||||
recipe = self.repos.recipes.by_group(group_id).get_one(recipe_slug)
|
||||
|
||||
if not recipe or not recipe.settings.public:
|
||||
raise HTTPException(404, "recipe not found")
|
||||
|
||||
return recipe
|
||||
@@ -1,10 +1,11 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import UUID4
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from mealie.db.db_setup import generate_session
|
||||
from mealie.repos.all_repositories import get_repositories
|
||||
from mealie.schema.recipe import Recipe
|
||||
from mealie.schema.response import ErrorResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -16,6 +17,6 @@ def get_shared_recipe(token_id: UUID4, session: Session = Depends(generate_sessi
|
||||
token_summary = db.recipe_share_tokens.get_one(token_id)
|
||||
|
||||
if token_summary is None:
|
||||
return None
|
||||
raise HTTPException(status_code=404, detail=ErrorResponse.respond("Token Not Found"))
|
||||
|
||||
return token_summary.recipe
|
||||
|
||||
Reference in New Issue
Block a user