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.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 fastapi import APIRouter, Depends, HTTPException
2from pydantic import UUID4
4from mealie.routes._base import controller
5from mealie.routes._base.base_controllers import BasePublicGroupExploreController
6from mealie.schema.make_dependable import make_dependable
7from mealie.schema.recipe.recipe import RecipeCategory, RecipeTag, RecipeTool
8from mealie.schema.recipe.recipe_category import CategoryOut, TagOut
9from mealie.schema.recipe.recipe_tool import RecipeToolOut
10from mealie.schema.response.pagination import PaginationBase, PaginationQuery
12base_prefix = "/organizers"
13categories_router = APIRouter(prefix=f"{base_prefix}/categories")
14tags_router = APIRouter(prefix=f"{base_prefix}/tags")
15tools_router = APIRouter(prefix=f"{base_prefix}/tools")
18@controller(categories_router)
19class PublicCategoriesController(BasePublicGroupExploreController):
20 @property
21 def categories(self):
22 return self.repos.categories
24 @categories_router.get("", response_model=PaginationBase[RecipeCategory])
25 def get_all(
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)
40 def get_one(self, item_id: UUID4) -> CategoryOut:
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)
49class PublicTagsController(BasePublicGroupExploreController):
50 @property
51 def tags(self):
52 return self.repos.tags
54 @tags_router.get("", response_model=PaginationBase[RecipeTag])
55 def get_all(
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)
70 def get_one(self, item_id: UUID4) -> TagOut:
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)
79class PublicToolsController(BasePublicGroupExploreController):
80 @property
81 def tools(self):
82 return self.repos.tools
84 @tools_router.get("", response_model=PaginationBase[RecipeTool])
85 def get_all(
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)
100 def get_one(self, item_id: UUID4) -> RecipeToolOut:
101 item = self.tools.get_one(item_id)
102 if not item:
103 raise HTTPException(404, "tool not found")
105 return item