4
from fastapi import APIRouter, Query, Request
5
from fastapi_filter import FilterDepends
7
from app.inventory.order.schemas import (
11
ExceptionResponseSchema,
15
from app.inventory.order.services import OrderService
17
order_router = APIRouter(
19
responses={"400": {"model": ExceptionResponseSchema}},
23
@order_router.get("", response_model=OrderListSchema)
26
model_filter: OrderFilter = FilterDepends(OrderFilter),
27
size: int = Query(ge=1, le=100, default=20),
29
data = await OrderService(request).list(model_filter, size)
30
cursor = model_filter.lsn__gt
31
return {'size': len(data), 'cursor': cursor, 'data': data}
34
@order_router.post("", response_model=OrderScheme)
35
async def order_create(request: Request, schema: OrderCreateScheme):
36
return await OrderService(request).create(obj=schema)
39
@order_router.get("/{order_id}")
40
async def order_get(request: Request, order_id: uuid.UUID) -> typing.Union[None, OrderScheme]:
41
return await OrderService(request).get(id=order_id)
44
@order_router.put("/{order_id}", response_model=OrderScheme)
45
async def order_update(request: Request, order_id: uuid.UUID, schema: OrderUpdateScheme):
46
return await OrderService(request).update(id=order_id, obj=schema)
49
@order_router.delete("/{order_id}")
50
async def order_delete(request: Request, order_id: uuid.UUID):
51
await OrderService(request).delete(id=order_id)