105 lines
2.5 KiB
Python
105 lines
2.5 KiB
Python
from fastapi import APIRouter, Path
|
|
|
|
from backend.dependecies import SessionDependency
|
|
from schemas.module import *
|
|
from services.module import ModuleService
|
|
|
|
router = APIRouter(tags=["modules"])
|
|
|
|
|
|
@router.get(
|
|
"/",
|
|
response_model=GetAllModulesResponse,
|
|
operation_id="get_modules",
|
|
)
|
|
async def get_modules(
|
|
session: SessionDependency,
|
|
):
|
|
return await ModuleService(session).get_all()
|
|
|
|
|
|
@router.get(
|
|
"/with-attributes",
|
|
response_model=GetAllWithAttributesResponse,
|
|
operation_id="get_modules_with_attributes",
|
|
)
|
|
async def get_modules_with_attributes(
|
|
session: SessionDependency,
|
|
):
|
|
return await ModuleService(session).get_with_attributes()
|
|
|
|
|
|
@router.get(
|
|
"/{pk}/with-attributes",
|
|
response_model=GetByIdWithAttributesResponse,
|
|
operation_id="get_module_with_attributes",
|
|
)
|
|
async def get_module_with_attributes(
|
|
session: SessionDependency,
|
|
pk: int = Path(),
|
|
):
|
|
return await ModuleService(session).get_by_id_with_attributes(pk)
|
|
|
|
|
|
@router.post(
|
|
"/",
|
|
response_model=CreateModuleResponse,
|
|
operation_id="create_module",
|
|
)
|
|
async def create_module(
|
|
session: SessionDependency,
|
|
request: CreateModuleRequest,
|
|
):
|
|
return await ModuleService(session).create(request)
|
|
|
|
|
|
@router.patch(
|
|
"/{pk}/common-info",
|
|
response_model=UpdateModuleCommonInfoResponse,
|
|
operation_id="update_module",
|
|
)
|
|
async def update_module_common_info(
|
|
session: SessionDependency,
|
|
request: UpdateModuleCommonInfoRequest,
|
|
pk: int = Path(),
|
|
):
|
|
return await ModuleService(session).update(pk, request)
|
|
|
|
|
|
@router.delete(
|
|
"/{pk}",
|
|
response_model=DeleteModuleResponse,
|
|
operation_id="delete_module",
|
|
)
|
|
async def delete_module(
|
|
session: SessionDependency,
|
|
pk: int = Path(),
|
|
):
|
|
return await ModuleService(session).delete(pk)
|
|
|
|
|
|
@router.post(
|
|
"/{moduleId}/attribute/{attributeId}",
|
|
response_model=AddAttributeResponse,
|
|
operation_id="add_attribute_to_module",
|
|
)
|
|
async def add_attribute_to_module(
|
|
session: SessionDependency,
|
|
module_id: int = Path(alias="moduleId"),
|
|
attribute_id: int = Path(alias="attributeId"),
|
|
):
|
|
return await ModuleService(session).add_attribute(module_id, attribute_id)
|
|
|
|
|
|
@router.delete(
|
|
"/{moduleId}/attribute/{attributeId}",
|
|
response_model=DeleteAttributeResponse,
|
|
operation_id="remove_attribute_from_module",
|
|
)
|
|
async def remove_attribute_from_module(
|
|
session: SessionDependency,
|
|
module_id: int = Path(alias="moduleId"),
|
|
attribute_id: int = Path(alias="attributeId"),
|
|
):
|
|
return await ModuleService(session).delete_attribute(module_id, attribute_id)
|