78 lines
1.9 KiB
Python
78 lines
1.9 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from backend.session import get_session
|
|
from schemas.attribute import *
|
|
from services.attribute import AttributeService
|
|
from services.auth import authorized_user
|
|
|
|
attribute_router = APIRouter(
|
|
prefix='/attribute',
|
|
tags=['attribute'],
|
|
)
|
|
|
|
|
|
@attribute_router.get(
|
|
'/',
|
|
response_model=GetAttributesResponse,
|
|
operation_id='get_all',
|
|
dependencies=[Depends(authorized_user)]
|
|
)
|
|
async def get_all(
|
|
session: Annotated[AsyncSession, Depends(get_session)]
|
|
):
|
|
return await AttributeService(session).get_all()
|
|
|
|
|
|
@attribute_router.get(
|
|
'/types',
|
|
response_model=GetAttributeTypesResponse,
|
|
operation_id='get_types',
|
|
dependencies=[Depends(authorized_user)]
|
|
)
|
|
async def get_types(
|
|
session: Annotated[AsyncSession, Depends(get_session)]
|
|
):
|
|
return await AttributeService(session).get_types()
|
|
|
|
|
|
@attribute_router.post(
|
|
'/',
|
|
response_model=CreateAttributeResponse,
|
|
operation_id='create',
|
|
dependencies=[Depends(authorized_user)]
|
|
)
|
|
async def create(
|
|
request: CreateAttributeRequest,
|
|
session: Annotated[AsyncSession, Depends(get_session)]
|
|
):
|
|
return await AttributeService(session).create(request)
|
|
|
|
|
|
@attribute_router.patch(
|
|
'/',
|
|
response_model=UpdateAttributeResponse,
|
|
operation_id='update',
|
|
dependencies=[Depends(authorized_user)]
|
|
)
|
|
async def update(
|
|
request: UpdateAttributeRequest,
|
|
session: Annotated[AsyncSession, Depends(get_session)]
|
|
):
|
|
return await AttributeService(session).update(request)
|
|
|
|
|
|
@attribute_router.delete(
|
|
'/{attribute_id}',
|
|
response_model=DeleteAttributeResponse,
|
|
operation_id='delete',
|
|
dependencies=[Depends(authorized_user)]
|
|
)
|
|
async def delete(
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
attribute_id: int,
|
|
):
|
|
return await AttributeService(session).delete(attribute_id)
|