3
from fastapi import APIRouter, Query, Depends
4
from fastapi_filter import FilterDepends
5
from starlette.requests import Request
7
from app.basic.uom.schemas import (
9
UomCategoryCreateScheme,
10
UomCategoryUpdateScheme,
11
UomCategoryListSchema,
12
UomCategoryFilter, ConvertSchema
14
from app.basic.uom.schemas import (
18
ExceptionResponseSchema,
22
from app.basic.uom.services.uom_category_service import UomCategoryService
23
from app.basic.uom.services.uom_service import UomService
25
uom_category_router = APIRouter(
26
responses={"400": {"model": ExceptionResponseSchema}},
28
uom_router = APIRouter(
29
responses={"400": {"model": ExceptionResponseSchema}},
33
@uom_category_router.get("", response_model=UomCategoryListSchema)
34
async def uom_category_list(
35
model_filter: UomCategoryFilter = FilterDepends(UomCategoryFilter),
36
size: int = Query(ge=1, le=100, default=100),
37
service: UomCategoryService = Depends()
39
data = await service.list(model_filter, size)
40
cursor = model_filter.lsn__gt
41
return {'size': len(data), 'cursor': cursor, 'data': data}
44
@uom_category_router.post("", response_model=UomCategoryScheme)
45
async def uom_category_create(schema: UomCategoryCreateScheme, service: UomCategoryService = Depends()):
46
return await service.create(obj=schema)
49
@uom_category_router.get("/{category_id}")
50
async def uom_category_get(category_id: uuid.UUID, service: UomCategoryService = Depends()):
51
return await service.get(id=category_id)
54
@uom_category_router.put("/{category_id}", response_model=UomCategoryScheme)
55
async def uom_category_update(category_id: uuid.UUID, schema: UomCategoryUpdateScheme, service: UomCategoryService = Depends()):
56
return await service.update(id=category_id, obj=schema)
59
@uom_category_router.delete("/{category_id}")
60
async def uom_category_delete(category_id: uuid.UUID, service: UomCategoryService = Depends()):
61
await service.delete(id=category_id)
65
@uom_router.get("", response_model=UomListSchema)
67
model_filter: UomFilter = FilterDepends(UomFilter),
68
size: int = Query(ge=1, le=100, default=100),
69
service: UomService = Depends()
71
data = await service.list(model_filter, size)
72
cursor = model_filter.lsn__gt
73
return {'size': len(data), 'cursor': cursor, 'data': data}
76
@uom_router.post("", response_model=UomScheme)
77
async def uom_create(schema: UomCreateScheme, service: UomService = Depends()):
78
return await service.create(obj=schema)
81
@uom_router.get("/{uom_id}")
82
async def uom_get(uom_id: uuid.UUID, service: UomService = Depends()):
83
return await service.get(id=uom_id)
86
@uom_router.put("/{uom_id}", response_model=UomScheme)
87
async def uom_update(uom_id: uuid.UUID, schema: UomUpdateScheme, service: UomService = Depends()):
88
return await service.update(id=uom_id, obj=schema)
91
@uom_router.delete("/{uom_id}")
92
async def uom_delete(uom_id: uuid.UUID, service: UomService = Depends()):
93
await service.delete(id=uom_id)
96
@uom_router.post("/convert", response_model=list[ConvertSchema])
97
async def uom_convert(schema: list[ConvertSchema], service: UomService = Depends()):
98
await service.convert(schema)