- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query, status, Request
|
|
from sqlalchemy.orm import Session
|
|
from typing import List, Optional, Any
|
|
|
|
from app.core.database.db_session import get_db
|
|
from app.core.permissions.RoleChecker import get_current_user
|
|
from app.models.UserModel import User
|
|
from app.services.ReviewModerationService import ReviewModerationService
|
|
from app.schemas.ReviewModeration import (
|
|
ReviewCreate,
|
|
ReviewModerateAction,
|
|
ReviewResponse,
|
|
CSATMetricsResponse
|
|
)
|
|
|
|
router = APIRouter(prefix="/api/v1/reviews", tags=["Review & Reputation Moderation"])
|
|
|
|
def get_review_service(request: Request, db: Session = Depends(get_db)) -> ReviewModerationService:
|
|
tenant_id = getattr(request.state, "tenant_id", "tenant_default")
|
|
return ReviewModerationService(db=db, tenant_id=tenant_id)
|
|
|
|
@router.post("", response_model=ReviewResponse, status_code=status.HTTP_201_CREATED)
|
|
def submit_review(
|
|
payload: ReviewCreate,
|
|
svc: ReviewModerationService = Depends(get_review_service)
|
|
) -> Any:
|
|
"""Submits a customer review for products, repair services, technicians, or store."""
|
|
return svc.submit_review(payload)
|
|
|
|
@router.get("", response_model=List[ReviewResponse])
|
|
def list_reviews(
|
|
skip: int = Query(0, ge=0),
|
|
limit: int = Query(50, ge=1, le=200),
|
|
moderation_status: Optional[str] = Query(None, alias="status"),
|
|
target_type: Optional[str] = None,
|
|
target_id: Optional[str] = None,
|
|
published_only: bool = False,
|
|
svc: ReviewModerationService = Depends(get_review_service)
|
|
) -> Any:
|
|
"""Lists customer reviews with filtering for admin queue or public storefront."""
|
|
return svc.list_reviews(
|
|
skip=skip,
|
|
limit=limit,
|
|
moderation_status=moderation_status,
|
|
target_type=target_type,
|
|
target_id=target_id,
|
|
published_only=published_only
|
|
)
|
|
|
|
@router.post("/{review_id}/moderate", response_model=ReviewResponse)
|
|
def moderate_review(
|
|
review_id: str,
|
|
action: ReviewModerateAction,
|
|
svc: ReviewModerationService = Depends(get_review_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Moderates a review (APPROVED, REJECTED, or FLAGGED) with audit trail."""
|
|
return svc.moderate_review(review_id=review_id, action=action, moderator_id=current_user.id)
|
|
|
|
@router.get("/csat-metrics", response_model=CSATMetricsResponse)
|
|
def get_csat_metrics(
|
|
target_type: str = Query(..., description="PRODUCT, REPAIR_SERVICE, TECHNICIAN, STORE"),
|
|
target_id: str = Query(...),
|
|
svc: ReviewModerationService = Depends(get_review_service)
|
|
) -> Any:
|
|
"""Retrieves CSAT metrics and average rating index for a product or repair technician."""
|
|
return svc.get_csat_metrics(target_type=target_type, target_id=target_id)
|