Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter, HTTPException, Depends | |
| from app.db.supabase import supabase | |
| from app.schemas.review import Review, ReviewCreate | |
| from datetime import date | |
| from app.dependencies.admin_auth import admin_auth | |
| router = APIRouter() | |
| def list_reviews(): | |
| res = supabase.table("reviews").select("*").order("created_at", desc=True).execute() | |
| return res.data | |
| def create_review(review: ReviewCreate): | |
| payload = review.model_dump() | |
| payload["created_at"] = date.today().isoformat() | |
| res = supabase.table("reviews").insert(payload).execute() | |
| if not res.data: | |
| raise HTTPException(status_code=400, detail="Failed to create review") | |
| return res.data[0] | |
| def update_review(review_id: int, review: ReviewCreate): | |
| res = supabase.table("reviews").update(review.model_dump()).eq("id", review_id).execute() | |
| if not res.data: | |
| raise HTTPException(status_code=404, detail="Review not found or update failed") | |
| return res.data[0] | |
| def delete_review(review_id: int): | |
| res = supabase.table("reviews").delete().eq("id", review_id).execute() | |
| if not res.data: | |
| raise HTTPException(status_code=404, detail="Review not found or delete failed") | |
| return {"detail": "Review deleted successfully"} | |