mirror of
http://88.130.71.182:3000/BlitTech/deals24togo_be.git
synced 2026-06-13 09:07:15 +00:00
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Favorites / wishlist endpoints."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from app.middleware.auth import get_current_user
|
|
from app.schemas.favorite import FavoriteCreate, FavoriteListResponse, FavoriteResponse
|
|
from app.services.favorite_service import FavoriteService
|
|
|
|
router = APIRouter(prefix="/favorites", tags=["Favorites"])
|
|
|
|
|
|
@router.post("/", response_model=FavoriteResponse, status_code=201)
|
|
def add_favorite(body: FavoriteCreate, user: dict = Depends(get_current_user)):
|
|
svc = FavoriteService()
|
|
return svc.add_favorite(user["id"], body.listing_id)
|
|
|
|
|
|
@router.delete("/{listing_id}")
|
|
def remove_favorite(listing_id: str, user: dict = Depends(get_current_user)):
|
|
svc = FavoriteService()
|
|
return svc.remove_favorite(user["id"], listing_id)
|
|
|
|
|
|
@router.get("/", response_model=FavoriteListResponse)
|
|
def list_favorites(user: dict = Depends(get_current_user)):
|
|
svc = FavoriteService()
|
|
return svc.list_favorites(user["id"])
|
|
|
|
|
|
@router.get("/check/{listing_id}")
|
|
def check_favorite(listing_id: str, user: dict = Depends(get_current_user)):
|
|
svc = FavoriteService()
|
|
return {"is_favorited": svc.is_favorited(user["id"], listing_id)}
|