4
from fastapi import APIRouter, Query, Request, Depends
5
from fastapi_filter import FilterDepends
7
from app.basic.store.schemas import (
11
ExceptionResponseSchema, StoreListSchema, StoreFilter
13
from app.basic.store.services import StoreService
14
from core.schemas.basic_schemes import ActionBaseSchame, ActionRescposeSchema
16
store_router = APIRouter(
17
responses={"400": {"model": ExceptionResponseSchema}},
21
@store_router.get("", response_model=StoreListSchema)
23
model_filter: StoreFilter = FilterDepends(StoreFilter),
24
size: int = Query(ge=1, le=100, default=100),
25
service: StoreService = 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
@store_router.post("", response_model=StoreScheme)
33
async def store_create(schema: StoreCreateScheme, service: StoreService = Depends()):
34
return await service.create(obj=schema)
37
@store_router.get("/{store_id}")
38
async def store_get(store_id: uuid.UUID, service: StoreService = Depends()) -> typing.Union[
40
return await service.get(id=store_id)
43
@store_router.put("/{store_id}", response_model=StoreScheme)
44
async def store_update(store_id: uuid.UUID, schema: StoreUpdateScheme,
45
service: StoreService = Depends()):
46
return await service.update(id=store_id, obj=schema)
49
@store_router.delete("/{store_id}")
50
async def store_delete(store_id: uuid.UUID, service: StoreService = Depends()):
51
await service.delete(id=store_id)
54
@store_router.post("/assign_store", response_model=ActionRescposeSchema)
55
async def assign_store(schema: ActionBaseSchame, service: StoreService = Depends()):
56
return await service.assign_store(store_id=schema.ids[0])