- Backend:
- Add address column to tickets and migration script
- Create guest users when user_id is missing; accept user_name and address
- Normalize stored image paths and expose absolute image_url
- Introduce utils for path normalization and ticket serialization
- Add CORS configuration for dashboard/emulator origins
- Tickets API:
- Serialize via ticket_to_dict with consistent schema
- Change status update to PATCH /api/tickets/{id}/status with JSON body
- Add DELETE /api/tickets/{id} with safe file removal
- Dashboard:
- Fetch tickets from backend, show thumbnails, absolute image URLs
- Status select + PATCH updates, toasts for feedback
- Add i18n key btn.viewDetails
- Mobile app:
- Persist device user_id via SharedPreferences
- Fetch and merge API tickets; prefer network imageUrl
- Submit user_name and address; delete via API when available
- Make location acquisition robust with fallbacks and non-blocking UX
- Android/deps:
- Disable Geolocator NMEA listener to prevent crashes
- Downgrade geolocator to ^11.0.0 for stability
BREAKING CHANGE:
- Status endpoint changed from PATCH /api/tickets/{id}?new_status=... to
PATCH /api/tickets/{id}/status with JSON body: {"status":"in_progress"}.
- /api/tickets and /api/tickets/{id} responses now use "id" (replacing
"ticket_id"), include "image_url", and normalize fields for clients. Update
consumers to use the new schema.
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
import uuid
|
|
from sqlalchemy import Column, String, Float, Enum, DateTime, ForeignKey, Index
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.database import Base
|
|
import enum
|
|
|
|
# ----------------------
|
|
# Enums
|
|
# ----------------------
|
|
class TicketStatus(str, enum.Enum):
|
|
NEW = "New"
|
|
IN_PROGRESS = "In Progress"
|
|
FIXED = "Fixed"
|
|
|
|
class SeverityLevel(str, enum.Enum):
|
|
LOW = "Low"
|
|
MEDIUM = "Medium"
|
|
HIGH = "High"
|
|
NA = "N/A"
|
|
|
|
# ----------------------
|
|
# User Model
|
|
# ----------------------
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()), index=True)
|
|
name = Column(String, nullable=False)
|
|
email = Column(String, unique=True, nullable=False)
|
|
|
|
tickets = relationship("Ticket", back_populates="user", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<User(id={self.id}, name={self.name}, email={self.email})>"
|
|
|
|
# ----------------------
|
|
# Ticket Model
|
|
# ----------------------
|
|
class Ticket(Base):
|
|
__tablename__ = "tickets"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()), index=True)
|
|
user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
image_path = Column(String, nullable=False)
|
|
category = Column(String, nullable=False)
|
|
severity = Column(Enum(SeverityLevel), nullable=False, default=SeverityLevel.NA)
|
|
description = Column(String, default="")
|
|
address = Column(String, nullable=True)
|
|
status = Column(Enum(TicketStatus), nullable=False, default=TicketStatus.NEW)
|
|
latitude = Column(Float, nullable=False)
|
|
longitude = Column(Float, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
user = relationship("User", back_populates="tickets")
|
|
|
|
__table_args__ = (
|
|
Index("idx_category_status", "category", "status"),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<Ticket(id={self.id}, category={self.category}, severity={self.severity}, status={self.status}, user_id={self.user_id})>"
|
|
|
|
# ----------------------
|
|
# Ticket Audit Model
|
|
# ----------------------
|
|
class TicketAudit(Base):
|
|
__tablename__ = "ticket_audit"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
ticket_id = Column(String, ForeignKey("tickets.id", ondelete="CASCADE"))
|
|
old_status = Column(Enum(TicketStatus))
|
|
new_status = Column(Enum(TicketStatus))
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now())
|