4
from fastapi import APIRouter, Query, Request, Depends
5
from fastapi_filter import FilterDepends
7
from app.inventory.order.schemas import (
11
ExceptionResponseSchema,
15
from app.inventory.order.schemas.order_schemas import AssignUser
16
from app.inventory.order.services import OrderService
18
order_router = APIRouter(
19
responses={"400": {"model": ExceptionResponseSchema}},
23
@order_router.get("", response_model=OrderListSchema)
25
model_filter: OrderFilter = FilterDepends(OrderFilter),
26
size: int = Query(ge=1, le=100, default=20),
27
service: OrderService = Depends()
29
data = await service.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(schema: OrderCreateScheme, service: OrderService = Depends()):
36
return await service.create(obj=schema)
39
@order_router.get("/{order_id}")
40
async def order_get(order_id: uuid.UUID, service: OrderService = Depends()):
41
return await service.get(id=order_id)
44
@order_router.put("/{order_id}", response_model=OrderScheme)
45
async def order_update(order_id: uuid.UUID, schema: OrderUpdateScheme, service: OrderService = Depends()):
46
return await service.update(id=order_id, obj=schema)
49
@order_router.delete("/{order_id}")
50
async def order_delete(order_id: uuid.UUID, service: OrderService = Depends()):
51
await service.delete(id=order_id)
54
@order_router.post("/assign_order", response_model=OrderScheme)
55
async def assign_order(schema: AssignUser, service: OrderService = Depends()):
56
return await service.assign_order(order_id=schema.order_id, user_id=schema.user_id)
59
@order_router.post("/order_start", response_model=list[OrderScheme])
60
async def order_start(schema: AssignUser, service: OrderService = Depends()):
61
return await service.order_start(ids=schema.ids, user_id=schema.user_id)