mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-27 20:55:12 -05:00
Feature/shareable recipes (#866)
* simplify context menu * move computed to comp-api * feat: ✨ create share tokens for recipes for sharing recieps to non-users * feat: ✨ shareable recipe links with og tags
This commit is contained in:
@@ -9,6 +9,7 @@ from . import (
|
||||
groups,
|
||||
parser,
|
||||
recipe,
|
||||
shared,
|
||||
shopping_lists,
|
||||
tags,
|
||||
tools,
|
||||
@@ -23,6 +24,7 @@ router.include_router(auth.router)
|
||||
router.include_router(users.router)
|
||||
router.include_router(groups.router)
|
||||
router.include_router(recipe.router)
|
||||
router.include_router(shared.router)
|
||||
router.include_router(comments.router)
|
||||
router.include_router(parser.router)
|
||||
router.include_router(unit_and_foods.router)
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import all_recipe_routes, bulk_actions, comments, image_and_assets, recipe_crud_routes, recipe_export
|
||||
from . import (
|
||||
all_recipe_routes,
|
||||
bulk_actions,
|
||||
comments,
|
||||
image_and_assets,
|
||||
recipe_crud_routes,
|
||||
recipe_export,
|
||||
shared_routes,
|
||||
)
|
||||
|
||||
prefix = "/recipes"
|
||||
|
||||
@@ -14,3 +22,4 @@ router.include_router(image_and_assets.user_router, prefix=prefix, tags=["Recipe
|
||||
router.include_router(comments.router, prefix=prefix, tags=["Recipe: Comments"])
|
||||
router.include_router(bulk_actions.router, prefix=prefix, tags=["Recipe: Bulk Actions"])
|
||||
router.include_router(bulk_actions.export_router, prefix=prefix, tags=["Recipe: Bulk Exports"])
|
||||
router.include_router(shared_routes.router, prefix=prefix, tags=["Recipe: Shared"])
|
||||
|
||||
21
mealie/routes/recipe/shared_routes.py
Normal file
21
mealie/routes/recipe/shared_routes.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import UUID4
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from mealie.db.database import get_database
|
||||
from mealie.db.db_setup import generate_session
|
||||
from mealie.schema.recipe import Recipe
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/shared/{token_id}", response_model=Recipe)
|
||||
def get_shared_recipe(token_id: UUID4, session: Session = Depends(generate_session)):
|
||||
db = get_database(session)
|
||||
|
||||
token_summary = db.recipe_share_tokens.get_one(token_id)
|
||||
|
||||
if token_summary is None:
|
||||
return None
|
||||
|
||||
return token_summary.recipe
|
||||
23
mealie/routes/shared/__init__.py
Normal file
23
mealie/routes/shared/__init__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import Depends
|
||||
|
||||
from mealie.routes.routers import UserAPIRouter
|
||||
from mealie.services._base_http_service.router_factory import RouterFactory
|
||||
from mealie.services.shared.recipe_shared_service import RecipeShareTokenSummary, SharedRecipeService
|
||||
|
||||
router = UserAPIRouter(prefix="/shared")
|
||||
|
||||
shared_router = RouterFactory(SharedRecipeService, prefix="/recipes", tags=["Shared: Recipes"])
|
||||
|
||||
|
||||
@shared_router.get("", response_model=list[RecipeShareTokenSummary])
|
||||
def get_all_shared(
|
||||
recipe_id: int = None,
|
||||
shared_recipe_service: SharedRecipeService = Depends(SharedRecipeService.private),
|
||||
):
|
||||
"""
|
||||
Get all shared recipes
|
||||
"""
|
||||
return shared_recipe_service.get_all(recipe_id)
|
||||
|
||||
|
||||
router.include_router(shared_router)
|
||||
Reference in New Issue
Block a user