40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from app.services.support_ticket import create_ticket, get_ticket_status
|
|
|
|
|
|
router = APIRouter(prefix="/api/support")
|
|
|
|
|
|
class TicketCreate(BaseModel):
|
|
name: str
|
|
email: str
|
|
subject: str
|
|
message: str
|
|
|
|
|
|
class TicketStatusRequest(BaseModel):
|
|
email: str
|
|
|
|
|
|
@router.post("/ticket")
|
|
def submit_ticket(payload: TicketCreate):
|
|
if not payload.subject.strip() or not payload.message.strip():
|
|
raise HTTPException(status_code=400, detail="Subject and message are required")
|
|
ticket = create_ticket(
|
|
name=payload.name.strip(),
|
|
email=payload.email.strip(),
|
|
subject=payload.subject.strip(),
|
|
message=payload.message.strip(),
|
|
)
|
|
return ticket
|
|
|
|
|
|
@router.post("/ticket/status/{ticket_id}")
|
|
def ticket_status(ticket_id: str, payload: TicketStatusRequest):
|
|
status = get_ticket_status(ticket_id.strip(), payload.email.strip())
|
|
if not status:
|
|
raise HTTPException(status_code=404, detail="Ticket not found")
|
|
return status
|