110 lines
2.6 KiB
Python
110 lines
2.6 KiB
Python
from fastapi import APIRouter, Path
|
|
|
|
from backend.dependecies import SessionDependency
|
|
from schemas.attribute import *
|
|
from services import AttributeService
|
|
|
|
router = APIRouter(tags=["attribute"])
|
|
|
|
|
|
@router.get(
|
|
"/",
|
|
response_model=GetAllAttributesResponse,
|
|
operation_id="get_attributes",
|
|
)
|
|
async def get_attributes(
|
|
session: SessionDependency,
|
|
):
|
|
return await AttributeService(session).get_all()
|
|
|
|
|
|
@router.post(
|
|
"/",
|
|
response_model=CreateAttributeResponse,
|
|
operation_id="create_attribute",
|
|
)
|
|
async def create_attribute(
|
|
session: SessionDependency,
|
|
request: CreateAttributeRequest,
|
|
):
|
|
return await AttributeService(session).create(request)
|
|
|
|
|
|
@router.patch(
|
|
"/{pk}",
|
|
response_model=UpdateAttributeResponse,
|
|
operation_id="update_attribute",
|
|
)
|
|
async def update_attribute(
|
|
session: SessionDependency,
|
|
request: UpdateAttributeRequest,
|
|
pk: int = Path(),
|
|
):
|
|
return await AttributeService(session).update(pk, request)
|
|
|
|
|
|
@router.delete(
|
|
"/{pk}",
|
|
response_model=DeleteAttributeResponse,
|
|
operation_id="delete_attribute",
|
|
)
|
|
async def delete_attribute(
|
|
session: SessionDependency,
|
|
pk: int = Path(),
|
|
):
|
|
return await AttributeService(session).delete(pk)
|
|
|
|
|
|
@router.post(
|
|
"/label",
|
|
response_model=UpdateAttributeLabelResponse,
|
|
operation_id="update_attribute_label",
|
|
)
|
|
async def update_attribute_label(
|
|
session: SessionDependency,
|
|
request: UpdateAttributeLabelRequest,
|
|
):
|
|
return await AttributeService(session).update_attribute_label(request)
|
|
|
|
|
|
@router.get(
|
|
"/type",
|
|
response_model=GetAllAttributeTypesResponse,
|
|
operation_id="get_attribute_types",
|
|
)
|
|
async def get_attribute_types(
|
|
session: SessionDependency,
|
|
):
|
|
return await AttributeService(session).get_attribute_types()
|
|
|
|
|
|
@router.get(
|
|
"/deal/{dealId}/module/{moduleId}",
|
|
response_model=GetDealModuleAttributesResponse,
|
|
operation_id="get_deal_module_attributes",
|
|
)
|
|
async def get_deal_module_attributes(
|
|
session: SessionDependency,
|
|
deal_id: int = Path(alias="dealId"),
|
|
module_id: int = Path(alias="moduleId"),
|
|
):
|
|
return await AttributeService(session).get_deal_module_attributes(
|
|
deal_id, module_id
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/deal/{dealId}/module/{moduleId}",
|
|
response_model=UpdateDealModuleAttributesResponse,
|
|
operation_id="update_deal_module_attributes",
|
|
)
|
|
async def update_deal_module_attributes(
|
|
session: SessionDependency,
|
|
request: UpdateDealModuleAttributesRequest,
|
|
deal_id: int = Path(alias="dealId"),
|
|
module_id: int = Path(alias="moduleId"),
|
|
):
|
|
return await AttributeService(session).update_deal_module_attributes(
|
|
deal_id, module_id, request
|
|
)
|