Coverage for opt/mealie/lib/python3.12/site-packages/mealie/routes/explore/controller_public_organizers.py: 55%
61 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
1from fastapi import APIRouter, Depends, HTTPException 1a
2from pydantic import UUID4 1a
4from mealie.routes._base import controller 1a
5from mealie.routes._base.base_controllers import BasePublicGroupExploreController 1a
6from mealie.schema.make_dependable import make_dependable 1a
7from mealie.schema.recipe.recipe import RecipeCategory, RecipeTag, RecipeTool 1a
8from mealie.schema.recipe.recipe_category import CategoryOut, TagOut 1a
9from mealie.schema.recipe.recipe_tool import RecipeToolOut 1a
10from mealie.schema.response.pagination import PaginationBase, PaginationQuery 1a
12base_prefix = "/organizers" 1a
13categories_router = APIRouter(prefix=f"{base_prefix}/categories") 1a
14tags_router = APIRouter(prefix=f"{base_prefix}/tags") 1a
15tools_router = APIRouter(prefix=f"{base_prefix}/tools") 1a
18@controller(categories_router) 1a
19class PublicCategoriesController(BasePublicGroupExploreController): 1a
20 @property 1a
21 def categories(self): 1a
22 return self.repos.categories
24 @categories_router.get("", response_model=PaginationBase[RecipeCategory]) 1a
25 def get_all( 1a
26 self,
27 q: PaginationQuery = Depends(make_dependable(PaginationQuery)),
28 search: str | None = None,
29 ) -> PaginationBase[RecipeCategory]:
30 response = self.categories.page_all(
31 pagination=q,
32 override=RecipeCategory,
33 search=search,
34 )
36 response.set_pagination_guides(self.get_explore_url_path(tags_router.url_path_for("get_all")), q.model_dump())
37 return response
39 @categories_router.get("/{item_id}", response_model=CategoryOut) 1a
40 def get_one(self, item_id: UUID4) -> CategoryOut: 1a
41 item = self.categories.get_one(item_id)
42 if not item:
43 raise HTTPException(404, "category not found")
45 return item
48@controller(tags_router) 1a
49class PublicTagsController(BasePublicGroupExploreController): 1a
50 @property 1a
51 def tags(self): 1a
52 return self.repos.tags
54 @tags_router.get("", response_model=PaginationBase[RecipeTag]) 1a
55 def get_all( 1a
56 self,
57 q: PaginationQuery = Depends(make_dependable(PaginationQuery)),
58 search: str | None = None,
59 ) -> PaginationBase[RecipeTag]:
60 response = self.tags.page_all(
61 pagination=q,
62 override=RecipeTag,
63 search=search,
64 )
66 response.set_pagination_guides(self.get_explore_url_path(tags_router.url_path_for("get_all")), q.model_dump())
67 return response
69 @tags_router.get("/{item_id}", response_model=TagOut) 1a
70 def get_one(self, item_id: UUID4) -> TagOut: 1a
71 item = self.tags.get_one(item_id)
72 if not item:
73 raise HTTPException(404, "tag not found")
75 return item
78@controller(tools_router) 1a
79class PublicToolsController(BasePublicGroupExploreController): 1a
80 @property 1a
81 def tools(self): 1a
82 return self.repos.tools
84 @tools_router.get("", response_model=PaginationBase[RecipeTool]) 1a
85 def get_all( 1a
86 self,
87 q: PaginationQuery = Depends(make_dependable(PaginationQuery)),
88 search: str | None = None,
89 ) -> PaginationBase[RecipeTool]:
90 response = self.tools.page_all(
91 pagination=q,
92 override=RecipeTool,
93 search=search,
94 )
96 response.set_pagination_guides(self.get_explore_url_path(tools_router.url_path_for("get_all")), q.model_dump())
97 return response
99 @tools_router.get("/{item_id}", response_model=RecipeToolOut) 1a
100 def get_one(self, item_id: UUID4) -> RecipeToolOut: 1a
101 item = self.tools.get_one(item_id)
102 if not item:
103 raise HTTPException(404, "tool not found")
105 return item