mirror of
http://88.130.71.182:3000/BlitTech/badoHair_be.git
synced 2026-06-13 08:49:46 +00:00
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from typing import Annotated
|
|
from fastapi import APIRouter, Depends, Query
|
|
import asyncpg
|
|
|
|
from app.core.pagination import pagination_params
|
|
from app.core.responses import ok, paginated
|
|
from app.dependencies import get_db
|
|
from app.services import product_service
|
|
|
|
router = APIRouter(prefix="/products", tags=["Products"])
|
|
|
|
|
|
@router.get("")
|
|
async def list_products(
|
|
pagination: Annotated[tuple, Depends(pagination_params)],
|
|
search: str | None = Query(None),
|
|
category: str | None = Query(None),
|
|
bestseller: bool = Query(False),
|
|
is_new: bool = Query(False),
|
|
exclude: str | None = Query(None, description="Exclude a product ID (e.g. for similar products)"),
|
|
db: asyncpg.Connection = Depends(get_db),
|
|
):
|
|
page, per_page, offset = pagination
|
|
products, total = await product_service.list_products(
|
|
db, page, per_page, offset,
|
|
include_hidden=False,
|
|
category=category,
|
|
bestseller=bestseller,
|
|
is_new=is_new,
|
|
search=search,
|
|
exclude_id=exclude,
|
|
)
|
|
return paginated(products, total, page, per_page)
|
|
|
|
|
|
@router.get("/{product_id}")
|
|
async def get_product(product_id: str, db: asyncpg.Connection = Depends(get_db)):
|
|
product = await product_service.get_product(db, product_id)
|
|
return ok(product)
|