mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-29 05:25:30 -05:00
feat(backend): ✨ add initial cookbook support
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import crud
|
||||
from . import cookbooks, crud
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
router.include_router(cookbooks.user_router)
|
||||
router.include_router(crud.user_router)
|
||||
router.include_router(crud.admin_router)
|
||||
|
||||
49
mealie/routes/groups/cookbooks.py
Normal file
49
mealie/routes/groups/cookbooks.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from fastapi import Depends
|
||||
|
||||
from mealie.routes.routers import UserAPIRouter
|
||||
from mealie.schema.cookbook.cookbook import CreateCookBook, ReadCookBook
|
||||
from mealie.services.cookbook import CookbookService
|
||||
|
||||
user_router = UserAPIRouter(prefix="/groups/cookbooks", tags=["Groups: Cookbooks"])
|
||||
|
||||
|
||||
@user_router.get("", response_model=list[ReadCookBook])
|
||||
def get_all_cookbook(cb_service: CookbookService = Depends(CookbookService.private)):
|
||||
""" Get cookbook from the Database """
|
||||
# Get Item
|
||||
return cb_service.get_all()
|
||||
|
||||
|
||||
@user_router.post("", response_model=ReadCookBook)
|
||||
def create_cookbook(data: CreateCookBook, cb_service: CookbookService = Depends(CookbookService.private)):
|
||||
""" Create cookbook in the Database """
|
||||
# Create Item
|
||||
return cb_service.create_one(data)
|
||||
|
||||
|
||||
@user_router.put("", response_model=list[ReadCookBook])
|
||||
def update_many(data: list[ReadCookBook], cb_service: CookbookService = Depends(CookbookService.private)):
|
||||
""" Create cookbook in the Database """
|
||||
# Create Item
|
||||
return cb_service.update_many(data)
|
||||
|
||||
|
||||
@user_router.get("/{id}", response_model=ReadCookBook)
|
||||
def get_cookbook(cb_service: CookbookService = Depends(CookbookService.write_existing)):
|
||||
""" Get cookbook from the Database """
|
||||
# Get Item
|
||||
return cb_service.cookbook
|
||||
|
||||
|
||||
@user_router.put("/{id}")
|
||||
def update_cookbook(data: CreateCookBook, cb_service: CookbookService = Depends(CookbookService.write_existing)):
|
||||
""" Update cookbook in the Database """
|
||||
# Update Item
|
||||
return cb_service.update_one(data)
|
||||
|
||||
|
||||
@user_router.delete("/{id}")
|
||||
def delete_cookbook(cd_service: CookbookService = Depends(CookbookService.write_existing)):
|
||||
""" Delete cookbook from the Database """
|
||||
# Delete Item
|
||||
return cd_service.delete_one()
|
||||
@@ -31,13 +31,13 @@ def get_recipe(recipe_service: RecipeService = Depends(RecipeService.read_existi
|
||||
|
||||
|
||||
@user_router.post("", status_code=201, response_model=str)
|
||||
def create_from_name(data: CreateRecipe, recipe_service: RecipeService = Depends(RecipeService.base)) -> str:
|
||||
def create_from_name(data: CreateRecipe, recipe_service: RecipeService = Depends(RecipeService.private)) -> str:
|
||||
""" Takes in a JSON string and loads data into the database as a new entry"""
|
||||
return recipe_service.create_recipe(data).slug
|
||||
|
||||
|
||||
@user_router.post("/create-url", status_code=201, response_model=str)
|
||||
def parse_recipe_url(url: CreateRecipeByURL, recipe_service: RecipeService = Depends(RecipeService.base)):
|
||||
def parse_recipe_url(url: CreateRecipeByURL, recipe_service: RecipeService = Depends(RecipeService.private)):
|
||||
""" Takes in a URL and attempts to scrape data and load it into the database """
|
||||
|
||||
recipe = create_from_url(url.url)
|
||||
|
||||
Reference in New Issue
Block a user