Coverage for opt/mealie/lib/python3.12/site-packages/mealie/routes/recipe/_base.py: 97%

36 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 15:32 +0000

1from functools import cached_property 1a

2 

3from fastapi.responses import JSONResponse 1a

4from pydantic import BaseModel, Field 1a

5 

6from mealie.db.models.household.cookbook import CookBook 1a

7from mealie.repos.all_repositories import get_repositories 1a

8from mealie.repos.repository_generic import RepositoryGeneric 1a

9from mealie.repos.repository_recipes import RepositoryRecipes 1a

10from mealie.routes._base import BaseCrudController 1a

11from mealie.routes._base.mixins import HttpRepo 1a

12from mealie.schema.cookbook.cookbook import ReadCookBook 1a

13from mealie.schema.recipe import Recipe 1a

14from mealie.schema.recipe.recipe import ( 1a

15 CreateRecipe, 

16) 

17from mealie.services.recipe.recipe_service import RecipeService 1a

18 

19 

20class JSONBytes(JSONResponse): 1a

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 """ 

25 

26 media_type = "application/json" 1a

27 

28 def render(self, content: bytes) -> bytes: 1a

29 return content 1cb

30 

31 

32class FormatResponse(BaseModel): 1a

33 jjson: list[str] = Field(..., alias="json") 1a

34 zip: list[str] 1a

35 

36 

37class BaseRecipeController(BaseCrudController): 1a

38 @cached_property 1a

39 def recipes(self) -> RepositoryRecipes: 1a

40 return self.repos.recipes 

41 

42 @cached_property 1a

43 def group_recipes(self) -> RepositoryRecipes: 1a

44 return get_repositories(self.session, group_id=self.group_id, household_id=None).recipes 1c

45 

46 @cached_property 1a

47 def group_cookbooks(self) -> RepositoryGeneric[ReadCookBook, CookBook]: 1a

48 return get_repositories(self.session, group_id=self.group_id, household_id=None).cookbooks 

49 

50 @cached_property 1a

51 def service(self) -> RecipeService: 1a

52 return RecipeService(self.repos, self.user, self.household, translator=self.translator) 1cdefghijkb

53 

54 @cached_property 1a

55 def mixins(self): 1a

56 return HttpRepo[CreateRecipe, Recipe, Recipe](self.recipes, self.logger)