no-mistakes(review): Guard photo cleanup; add transitions helper and assign auto-advance
This commit is contained in:
+24
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -32,6 +33,8 @@ from app.schemas.ticket import (
|
||||
from app.services import ticket as ticket_service
|
||||
from app.services.sla import get_sla_status
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/tickets", tags=["tickets"])
|
||||
|
||||
# Ensure uploads directory exists
|
||||
@@ -224,6 +227,19 @@ async def list_tickets(
|
||||
return TicketListResponse(items=items, total=total, page=page, page_size=page_size)
|
||||
|
||||
|
||||
@router.get("/{ticket_id}/transitions")
|
||||
async def get_ticket_transitions(
|
||||
ticket_id: int,
|
||||
db: Annotated[AsyncSession, Depends(get_db)],
|
||||
) -> dict:
|
||||
"""Return the valid next statuses for a ticket's current status."""
|
||||
ticket = await ticket_service.get_ticket(db, ticket_id)
|
||||
return {
|
||||
"current_status": ticket.status,
|
||||
"transitions": ticket_service.VALID_TRANSITIONS.get(ticket.status, []),
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{ticket_id}", response_model=TicketOut)
|
||||
async def get_ticket(
|
||||
ticket_id: int,
|
||||
@@ -266,7 +282,14 @@ async def delete_ticket(
|
||||
for photo in ticket.photos:
|
||||
if photo.photo_url:
|
||||
name = photo.photo_url.rsplit("/", 1)[-1]
|
||||
(UPLOADS_DIR / name).unlink(missing_ok=True)
|
||||
try:
|
||||
(UPLOADS_DIR / name).unlink(missing_ok=True)
|
||||
except OSError:
|
||||
logger.warning(
|
||||
"Could not remove orphaned photo file %s for ticket %s",
|
||||
name,
|
||||
ticket_id,
|
||||
)
|
||||
|
||||
|
||||
# ── Status Transitions (convenience endpoints) ───────────────────────
|
||||
|
||||
Reference in New Issue
Block a user