ifixkart-admin/Backend/app/api/v1/routers/CrmTaskCalendarRouter.py
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- 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
2026-10-13 12:59:47 +05:30

97 lines
3.4 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Query, status
from sqlalchemy.orm import Session
from typing import List, Optional
from datetime import datetime
from app.core.database.db_session import get_db
from app.schemas.Crm import (
CrmTaskCreate, CrmTaskUpdate, CrmTaskResponse,
CrmCalendarEventCreate, CrmCalendarEventUpdate, CrmCalendarEventResponse
)
from app.services.CrmTaskCalendarService import CrmTaskCalendarService
router = APIRouter(prefix="/api/v1/crm", tags=["CRM Tasks & Calendar"])
# --- TASKS ENDPOINTS ---
@router.get("/tasks", response_model=List[CrmTaskResponse])
def get_crm_tasks(
location_id: Optional[str] = Query(None),
status: Optional[str] = Query(None),
assignee_id: Optional[str] = Query(None),
entity_type: Optional[str] = Query(None),
entity_id: Optional[str] = Query(None),
db: Session = Depends(get_db)
):
return CrmTaskCalendarService.list_tasks(
db, location_id=location_id, status=status, assignee_id=assignee_id,
entity_type=entity_type, entity_id=entity_id
)
@router.post("/tasks", response_model=CrmTaskResponse, status_code=status.HTTP_201_CREATED)
def create_crm_task(
payload: CrmTaskCreate,
db: Session = Depends(get_db)
):
return CrmTaskCalendarService.create_task(db, payload)
@router.put("/tasks/{task_id}", response_model=CrmTaskResponse)
def update_crm_task(
task_id: str,
payload: CrmTaskUpdate,
db: Session = Depends(get_db)
):
task = CrmTaskCalendarService.update_task(db, task_id, payload)
if not task:
raise HTTPException(status_code=404, detail="CRM task not found")
return task
@router.delete("/tasks/{task_id}")
def delete_crm_task(
task_id: str,
db: Session = Depends(get_db)
):
success = CrmTaskCalendarService.delete_task(db, task_id)
if not success:
raise HTTPException(status_code=404, detail="CRM task not found")
return {"message": "Task deleted successfully"}
# --- CALENDAR ENDPOINTS ---
@router.get("/calendar", response_model=List[CrmCalendarEventResponse])
def get_calendar_events(
location_id: Optional[str] = Query(None),
start_from: Optional[datetime] = Query(None),
end_until: Optional[datetime] = Query(None),
db: Session = Depends(get_db)
):
return CrmTaskCalendarService.list_calendar_events(
db, location_id=location_id, start_from=start_from, end_until=end_until
)
@router.post("/calendar", response_model=CrmCalendarEventResponse, status_code=status.HTTP_201_CREATED)
def create_calendar_event(
payload: CrmCalendarEventCreate,
db: Session = Depends(get_db)
):
return CrmTaskCalendarService.create_calendar_event(db, payload)
@router.put("/calendar/{event_id}", response_model=CrmCalendarEventResponse)
def update_calendar_event(
event_id: str,
payload: CrmCalendarEventUpdate,
db: Session = Depends(get_db)
):
event = CrmTaskCalendarService.update_calendar_event(db, event_id, payload)
if not event:
raise HTTPException(status_code=404, detail="Calendar event not found")
return event
@router.delete("/calendar/{event_id}")
def delete_calendar_event(
event_id: str,
db: Session = Depends(get_db)
):
success = CrmTaskCalendarService.delete_calendar_event(db, event_id)
if not success:
raise HTTPException(status_code=404, detail="Calendar event not found")
return {"message": "Calendar event deleted successfully"}