Coverage for opt/mealie/lib/python3.12/site-packages/mealie/routes/recipe/_base.py: 100%
36 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
1from functools import cached_property
3from fastapi.responses import JSONResponse
4from pydantic import BaseModel, Field
6from mealie.db.models.household.cookbook import CookBook
7from mealie.repos.all_repositories import get_repositories
8from mealie.repos.repository_generic import RepositoryGeneric
9from mealie.repos.repository_recipes import RepositoryRecipes
10from mealie.routes._base import BaseCrudController
11from mealie.routes._base.mixins import HttpRepo
12from mealie.schema.cookbook.cookbook import ReadCookBook
13from mealie.schema.recipe import Recipe
14from mealie.schema.recipe.recipe import (
15 CreateRecipe,
16)
17from mealie.services.recipe.recipe_service import RecipeService
20class JSONBytes(JSONResponse):
21 """
22 JSONBytes overrides the render method to return the bytes instead of a string.
23 You can use this when you want to use orjson and bypass the jsonable_encoder
24 """
26 media_type = "application/json"
28 def render(self, content: bytes) -> bytes:
29 return content
32class FormatResponse(BaseModel):
33 jjson: list[str] = Field(..., alias="json")
34 zip: list[str]
37class BaseRecipeController(BaseCrudController):
38 @cached_property
39 def recipes(self) -> RepositoryRecipes:
40 return self.repos.recipes
42 @cached_property
43 def group_recipes(self) -> RepositoryRecipes:
44 return get_repositories(self.session, group_id=self.group_id, household_id=None).recipes
46 @cached_property
47 def group_cookbooks(self) -> RepositoryGeneric[ReadCookBook, CookBook]:
48 return get_repositories(self.session, group_id=self.group_id, household_id=None).cookbooks
50 @cached_property
51 def service(self) -> RecipeService:
52 return RecipeService(self.repos, self.user, self.household, translator=self.translator)
54 @cached_property
55 def mixins(self):
56 return HttpRepo[CreateRecipe, Recipe, Recipe](self.recipes, self.logger)