ifixkart-backend/app/api/v1/routers/RoleNotificationSettingsRouter.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

61 lines
2.8 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from sqlalchemy import select
from typing import List
from app.core.database.db_session import get_db
from app.core.permissions.RoleChecker import get_current_user, RoleChecker
from app.models.UserModel import User
from app.models.RoleNotificationSettingModel import RoleNotificationSetting
from app.schemas.RoleNotificationSettingSchema import (
RoleNotificationSettingResponse,
RoleNotificationSettingCreate,
RoleNotificationSettingUpdate
)
router = APIRouter(prefix="/api/v1/settings/notifications", tags=["Role Notification Settings"])
@router.get("/", response_model=List[RoleNotificationSettingResponse])
def get_settings(db: Session = Depends(get_db), current_user: User = Depends(RoleChecker(["super admin", "admin"]))):
settings = db.execute(select(RoleNotificationSetting)).scalars().all()
return settings
@router.post("/", response_model=RoleNotificationSettingResponse, status_code=status.HTTP_201_CREATED)
def create_setting(payload: RoleNotificationSettingCreate, db: Session = Depends(get_db), current_user: User = Depends(RoleChecker(["super admin"]))):
existing = db.execute(select(RoleNotificationSetting).where(
RoleNotificationSetting.role_name == payload.role_name,
RoleNotificationSetting.event_type == payload.event_type
)).scalars().first()
if existing:
raise HTTPException(status_code=400, detail="Setting for this role and event already exists.")
setting = RoleNotificationSetting(**payload.model_dump())
db.add(setting)
db.commit()
db.refresh(setting)
return setting
@router.put("/{setting_id}", response_model=RoleNotificationSettingResponse)
def update_setting(setting_id: str, payload: RoleNotificationSettingUpdate, db: Session = Depends(get_db), current_user: User = Depends(RoleChecker(["super admin", "admin"]))):
setting = db.execute(select(RoleNotificationSetting).where(RoleNotificationSetting.setting_id == setting_id)).scalars().first()
if not setting:
raise HTTPException(status_code=404, detail="Setting not found.")
if payload.channel_email is not None:
setting.channel_email = payload.channel_email
if payload.channel_whatsapp is not None:
setting.channel_whatsapp = payload.channel_whatsapp
db.commit()
db.refresh(setting)
return setting
@router.delete("/{setting_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_setting(setting_id: str, db: Session = Depends(get_db), current_user: User = Depends(RoleChecker(["super admin"]))):
setting = db.execute(select(RoleNotificationSetting).where(RoleNotificationSetting.setting_id == setting_id)).scalars().first()
if not setting:
raise HTTPException(status_code=404, detail="Setting not found.")
db.delete(setting)
db.commit()
return None