ifixkart-backend/app/api/v1/routers/RefundRouter.py
adithiyan 10bfba7d58 feat: add warranties, refunds, notifications, CRM calendar, system config & delivery modules
- New models: WarrantyModel, WalletModel, SystemConfigModel
- New schemas: WarrantySchema, RefundSchema, SystemConfig, CrmTaskCalendar, NotificationTemplate, NotificationGateway, RepairErp, ReviewModeration, InventoryPos, MultiDashboard, BillingFinance
- New services: WarrantyService, RefundService, CrmService, CrmTaskCalendarService, DeliveryService, EmailTemplateService, InventoryPosService, MultiDashboardService, NotificationGatewayService, RepairErpService, ReviewModerationService, SystemConfigService, TemplateService, CreditService
- Updated routers: AdminOrder, BillingFinance, Cart, Catalog, Checkout, Crm, InventoryPos, NotificationGateway, RolePermission, ServiceJob, Settings, Storefront, UserCreation
- Updated models: Inventory, Notification, Order, Product, Service, Setting, SystemConfig, User
- Updated core: database init, invoice generator, main app
- Added WarrantyRouter with full CRUD and claim flow
2026-10-13 22:05:16 +05:30

60 lines
2.3 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.RefundService import RefundService
from app.schemas.RefundSchema import (
RefundRequestCreate, RefundRequestApprove, RefundRequestReject, RefundRequestResponse
)
router = APIRouter(prefix="/api/v1/refunds", tags=["Refund Management"])
def get_refund_service(request: Request, db: Session = Depends(get_db)) -> RefundService:
tenant_id = getattr(request.state, "tenant_id", "tenant_default")
return RefundService(db=db, tenant_id=tenant_id)
@router.post("/request", response_model=RefundRequestResponse, status_code=status.HTTP_201_CREATED)
def request_refund(
payload: RefundRequestCreate,
svc: RefundService = Depends(get_refund_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Submits a new refund request with evidence media."""
return svc.request_refund(payload, user_id=current_user.user_id)
@router.post("/{refund_id}/approve", response_model=RefundRequestResponse)
def approve_refund(
refund_id: str,
payload: RefundRequestApprove,
svc: RefundService = Depends(get_refund_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Approves a refund request."""
return svc.approve_refund(refund_id=refund_id, data=payload, user_id=current_user.user_id)
@router.post("/{refund_id}/reject", response_model=RefundRequestResponse)
def reject_refund(
refund_id: str,
payload: RefundRequestReject,
svc: RefundService = Depends(get_refund_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Rejects a refund request."""
return svc.reject_refund(refund_id=refund_id, data=payload, user_id=current_user.user_id)
@router.get("", response_model=List[RefundRequestResponse])
def list_refunds(
entity_type: Optional[str] = Query(None),
status: Optional[str] = Query(None),
svc: RefundService = Depends(get_refund_service),
current_user: User = Depends(get_current_user)
) -> Any:
"""Lists all refund requests based on filters."""
return svc.list_refunds(entity_type=entity_type, status=status)