4
from fastapi import APIRouter, Query, Request, Depends
5
from fastapi_filter import FilterDepends
7
from app.inventory.order.schemas.suggest_schemas import (
15
from app.inventory.order.services.suggest_service import SuggestService
17
suggest_router = APIRouter(
21
@suggest_router.get("", response_model=SuggestListSchema)
22
async def suggest_list(
23
model_filter: SuggestFilter = FilterDepends(SuggestFilter),
24
size: int = Query(ge=1, le=100, default=20),
25
service: SuggestService = Depends()
27
data = await service.list(model_filter, size)
28
cursor = model_filter.lsn__gt
29
return {'size': len(data), 'cursor': cursor, 'data': data}
32
@suggest_router.post("", response_model=SuggestScheme)
33
async def suggest_create(schema: SuggestCreateScheme, service: SuggestService = Depends()):
34
return await service.create(obj=schema)
37
@suggest_router.get("/{suggest_id}", response_model=SuggestScheme)
38
async def suggest_get(suggest_id: uuid.UUID, service: SuggestService = Depends()) -> typing.Union[None, SuggestScheme]:
39
return await service.get(id=suggest_id)
42
@suggest_router.put("/{suggest_id}", response_model=SuggestScheme)
43
async def suggest_update(suggest_id: uuid.UUID, schema: SuggestUpdateScheme, service: SuggestService = Depends()):
44
return await service.update(id=suggest_id, obj=schema)
47
@suggest_router.delete("/{suggest_id}")
48
async def suggest_delete(suggest_id: uuid.UUID, service: SuggestService = Depends()):
49
await service.delete(id=suggest_id)
51
@suggest_router.post("/confirm", responses={200: {'model': list[SuggestScheme]}})
52
async def action_suggest_confirm(schema: SuggestConfirmScheme, service: SuggestService = Depends()):
53
return await service.suggest_confirm(suggest_ids=schema.ids, value=schema.value)