4
from fastapi import APIRouter, Query, Request, Depends
5
from fastapi_filter import FilterDepends
7
from app.inventory.location.schemas import (
11
ExceptionResponseSchema,
15
from app.inventory.location.services import LocationService
17
location_router = APIRouter(
18
responses={"400": {"model": ExceptionResponseSchema}},
22
@location_router.get("", response_model=LocationListSchema)
23
async def location_list(
24
model_filter: LocationFilter = FilterDepends(LocationFilter),
25
size: int = Query(ge=1, le=100, default=100),
26
service: LocationService = Depends()
28
data = await service.list(model_filter, size)
29
cursor = model_filter.lsn__gt
30
return {'size': len(data), 'cursor': cursor, 'data': data}
32
@location_router.post("", response_model=LocationScheme)
33
async def location_create(schema: LocationCreateScheme, service: LocationService = Depends()):
34
return await service.create(obj=schema)
37
@location_router.get("/{Location_id}")
38
async def location_get(location_id: uuid.UUID, service: LocationService = Depends()) -> typing.Union[None, LocationScheme]:
39
return await service.get(id=location_id)
42
@location_router.put("/{location_id}", response_model=LocationScheme)
43
async def location_update(location_id: uuid.UUID, schema: LocationUpdateScheme, service: LocationService = Depends()):
44
return await service.update(id=location_id, obj=schema)
47
@location_router.delete("/{location_id}")
48
async def location_delete(location_id: uuid.UUID, service: LocationService = Depends()):
49
await service.delete(id=location_id)