fooder-api/fooder/view/product.py

30 lines
819 B
Python
Raw Normal View History

2023-04-01 16:19:12 +02:00
from fastapi import APIRouter, Depends, Request
from ..model.product import Product, CreateProductPayload, ListProductPayload
from ..controller.product import ListProduct, CreateProduct
2023-04-01 20:13:11 +02:00
from typing import Optional
2023-04-01 16:19:12 +02:00
router = APIRouter(tags=["product"])
2023-04-01 20:23:04 +02:00
@router.get("", response_model=ListProductPayload)
2023-04-01 16:19:12 +02:00
async def list_product(
request: Request,
controller: ListProduct = Depends(ListProduct),
limit: int = 10,
offset: int = 0,
2023-04-01 20:13:11 +02:00
q: Optional[str] = None,
2023-04-01 16:19:12 +02:00
):
return ListProductPayload(
2023-04-01 20:13:11 +02:00
products=[p async for p in controller.call(limit=limit, offset=offset, q=q)]
2023-04-01 16:19:12 +02:00
)
2023-04-01 20:23:04 +02:00
@router.post("", response_model=Product)
2023-04-01 16:19:12 +02:00
async def create_product(
request: Request,
data: CreateProductPayload,
contoller: CreateProduct = Depends(CreateProduct),
):
return await contoller.call(data)