mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-14 11:53:11 -05:00
Feature/restore-recipe-functionality (#810)
* feat(frontend): ✨ add back support for assets * feat(backend): ✨ add back support for assets * feat(frontend): ✨ add support for recipe tools * feat(backend): ✨ add support for recipe tools * feat(frontend): ✨ add onHand support for recipe toosl * feat(backend): ✨ add onHand support for backend * refactor(frontend): ♻️ move items to recipe folder and break apart types * feat(frontend): ✨ add support for recipe comments * feat(backend): ✨ Add support for recipe comments * fix(backend): 💥 disable comments import * fix(frontend): 🐛 fix rendering issue with titles when moving steps * add tools to changelog * fix type errors Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
52
mealie/services/recipe/recipe_comments_service.py
Normal file
52
mealie/services/recipe/recipe_comments_service.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import cached_property
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from mealie.schema.recipe.recipe_comments import (
|
||||
RecipeCommentCreate,
|
||||
RecipeCommentOut,
|
||||
RecipeCommentSave,
|
||||
RecipeCommentUpdate,
|
||||
)
|
||||
from mealie.services._base_http_service.crud_http_mixins import CrudHttpMixins
|
||||
from mealie.services._base_http_service.http_services import UserHttpService
|
||||
from mealie.services.events import create_recipe_event
|
||||
|
||||
|
||||
class RecipeCommentsService(
|
||||
CrudHttpMixins[RecipeCommentOut, RecipeCommentCreate, RecipeCommentCreate],
|
||||
UserHttpService[UUID, RecipeCommentOut],
|
||||
):
|
||||
event_func = create_recipe_event
|
||||
_restrict_by_group = False
|
||||
_schema = RecipeCommentOut
|
||||
|
||||
@cached_property
|
||||
def dal(self):
|
||||
return self.db.comments
|
||||
|
||||
def _check_comment_belongs_to_user(self) -> None:
|
||||
if self.item.user_id != self.user.id and not self.user.admin:
|
||||
raise HTTPException(detail="Comment does not belong to user")
|
||||
|
||||
def populate_item(self, id: UUID) -> RecipeCommentOut:
|
||||
self.item = self.dal.get_one(id)
|
||||
return self.item
|
||||
|
||||
def get_all(self) -> list[RecipeCommentOut]:
|
||||
return self.dal.get_all()
|
||||
|
||||
def create_one(self, data: RecipeCommentCreate) -> RecipeCommentOut:
|
||||
save_data = RecipeCommentSave(text=data.text, user_id=self.user.id, recipe_id=data.recipe_id)
|
||||
return self._create_one(save_data)
|
||||
|
||||
def update_one(self, data: RecipeCommentUpdate, item_id: UUID = None) -> RecipeCommentOut:
|
||||
self._check_comment_belongs_to_user()
|
||||
return self._update_one(data, item_id)
|
||||
|
||||
def delete_one(self, item_id: UUID = None) -> RecipeCommentOut:
|
||||
self._check_comment_belongs_to_user()
|
||||
return self._delete_one(item_id)
|
||||
37
mealie/services/recipe/recipe_tool_service.py
Normal file
37
mealie/services/recipe/recipe_tool_service.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import cached_property
|
||||
|
||||
from mealie.schema.recipe.recipe_tool import RecipeTool, RecipeToolCreate
|
||||
from mealie.services._base_http_service.crud_http_mixins import CrudHttpMixins
|
||||
from mealie.services._base_http_service.http_services import UserHttpService
|
||||
from mealie.services.events import create_recipe_event
|
||||
|
||||
|
||||
class RecipeToolService(
|
||||
CrudHttpMixins[RecipeTool, RecipeToolCreate, RecipeToolCreate],
|
||||
UserHttpService[int, RecipeTool],
|
||||
):
|
||||
event_func = create_recipe_event
|
||||
_restrict_by_group = False
|
||||
_schema = RecipeTool
|
||||
|
||||
@cached_property
|
||||
def dal(self):
|
||||
return self.db.tools
|
||||
|
||||
def populate_item(self, id: int) -> RecipeTool:
|
||||
self.item = self.dal.get_one(id)
|
||||
return self.item
|
||||
|
||||
def get_all(self) -> list[RecipeTool]:
|
||||
return self.dal.get_all()
|
||||
|
||||
def create_one(self, data: RecipeToolCreate) -> RecipeTool:
|
||||
return self._create_one(data)
|
||||
|
||||
def update_one(self, data: RecipeTool, item_id: int = None) -> RecipeTool:
|
||||
return self._update_one(data, item_id)
|
||||
|
||||
def delete_one(self, id: int = None) -> RecipeTool:
|
||||
return self._delete_one(id)
|
||||
Reference in New Issue
Block a user