3
from fastapi import APIRouter, Query, Depends
4
from fastapi_filter import FilterDepends
5
from starlette.requests import Request
7
from app.basic.partner.schemas import (
11
ExceptionResponseSchema, PartnerListSchema, PartnerFilter
13
from app.basic.partner.services import PartnerService
15
partner_router = APIRouter(
17
responses={"400": {"model": ExceptionResponseSchema}},
21
@partner_router.get("", response_model=PartnerListSchema)
22
async def partner_list(
23
model_filter: PartnerFilter = FilterDepends(PartnerFilter),
24
size: int = Query(ge=1, le=100, default=100),
25
service: PartnerService = 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
@partner_router.post("", response_model=PartnerScheme)
33
async def partner_create(schema: PartnerCreateScheme, service: PartnerService = Depends()):
34
return await service.create(obj=schema)
37
@partner_router.get("/{partner_id}")
38
async def partner_get(partner_id: uuid.UUID, service: PartnerService = Depends()):
39
return await service.get(id=partner_id)
42
@partner_router.put("/{partner_id}", response_model=PartnerScheme)
43
async def partner_update(partner_id: uuid.UUID, schema: PartnerUpdateScheme, service: PartnerService = Depends()):
44
return await service.update(id=partner_id, obj=schema)
47
@partner_router.delete("/{partner_id}")
48
async def partner_delete(partner_id: uuid.UUID, service: PartnerService = Depends()):
49
await service.delete(id=partner_id)