redis implemntations and api setup completed

This commit is contained in:
2025-01-25 20:59:47 +03:00
parent 32022ca521
commit 3d5a43220e
138 changed files with 2888 additions and 1117 deletions

View File

@@ -17,7 +17,7 @@ class CategoryCreate(CategoryBase):
class CategoryResponse(CategoryBase):
children: List['CategoryResponse'] = []
children: List["CategoryResponse"] = []
parent_id: Optional[str] = None
@@ -28,7 +28,7 @@ class CategoryNode:
name: str
description: Optional[str]
parent_id: Optional[str] = None
children: List['CategoryNode'] = field(default_factory=list)
children: List["CategoryNode"] = field(default_factory=list)
# Category Service for managing the hierarchy
@@ -41,7 +41,7 @@ class CategoryService:
id=category.id,
name=category.name,
description=category.description,
parent_id=category.parent_id
parent_id=category.parent_id,
)
self.categories[category.id] = node
@@ -61,7 +61,9 @@ class CategoryService:
while current:
path.append(current)
current = self.categories.get(current.parent_id) if current.parent_id else None
current = (
self.categories.get(current.parent_id) if current.parent_id else None
)
return list(reversed(path))
@@ -85,9 +87,8 @@ class CategoryEndpointFactory:
endpoint_function=self.create_category,
request_model=CategoryCreate,
response_model=CategoryResponse,
is_auth_required=True
is_auth_required=True,
),
# Get category tree endpoint
EndpointFactoryConfig(
url_prefix=base_prefix,
@@ -99,9 +100,8 @@ class CategoryEndpointFactory:
description="Get category and its children",
endpoint_function=self.get_category_tree,
response_model=CategoryResponse,
is_auth_required=True
is_auth_required=True,
),
# Get category path endpoint
EndpointFactoryConfig(
url_prefix=base_prefix,
@@ -113,15 +113,15 @@ class CategoryEndpointFactory:
description="Get full path from root to this category",
endpoint_function=self.get_category_path,
response_model=List[CategoryResponse],
is_auth_required=True
)
is_auth_required=True,
),
]
return RouteFactoryConfig(
name="categories",
tags=["Categories"],
prefix=base_prefix,
endpoints=endpoints
endpoints=endpoints,
)
async def create_category(self, category: CategoryCreate) -> CategoryResponse:
@@ -146,7 +146,7 @@ class CategoryEndpointFactory:
name=node.name,
description=node.description,
parent_id=node.parent_id,
children=[self._convert_to_response(child) for child in node.children]
children=[self._convert_to_response(child) for child in node.children],
)
@@ -156,10 +156,7 @@ def create_category_router(base_prefix: str = "/api/v1") -> APIRouter:
factory = CategoryEndpointFactory(category_service)
route_config = factory.create_route_config(base_prefix)
router = APIRouter(
prefix=route_config.prefix,
tags=route_config.tags
)
router = APIRouter(prefix=route_config.prefix, tags=route_config.tags)
for endpoint in route_config.endpoints:
router.add_api_route(
@@ -169,7 +166,7 @@ def create_category_router(base_prefix: str = "/api/v1") -> APIRouter:
response_model=endpoint.response_model,
summary=endpoint.summary,
description=endpoint.description,
**endpoint.extra_options
**endpoint.extra_options,
)
return router
return router