mirror of
http://88.130.71.182:3000/BlitTech/badoHair_be.git
synced 2026-06-12 23:23:22 +00:00
Initial Commit
This commit is contained in:
39
app/routers/products.py
Normal file
39
app/routers/products.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user