feat(api): implement Pydantic models for data validation

This commit is contained in:
kiskaadee committed 2026-05-30 14:34:22 -05:00
1 parent 5bab3ebf68
commit 56e43746c9
7 files changed
+261 -1

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
from api.models.user import User
from api.models.sculpture import SculptureStatus, Sculpture, SculptureDetails
from api.models.checkin import CheckInRecord, CheckInResponse
from api.models.ticket import TicketStatus, Ticket, ReportVerificationRequest
from api.models.auth import LoginRequest, LoginResponse
__all__ = [
"User",
"SculptureStatus",
"Sculpture",
"SculptureDetails",
"CheckInRecord",
"CheckInResponse",
"TicketStatus",
"Ticket",
"ReportVerificationRequest",
"LoginRequest",
"LoginResponse"
]
+33
View File
@@ -0,0 +1,33 @@
from pydantic import BaseModel, Field
class LoginRequest(BaseModel):
"""
Request model for Google SSO Authentication.
"""
id_token: str = Field(..., description="The ID token returned by Google OAuth flow.")
model_config = {
"json_schema_extra": {
"example": {
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJzdWIiOiIxMjM0NTY3ODkwIiwiYXVkIjoiY2xpZW50X2lkIiwiZXhwIjoxNDY5NDkwMDAwfQ..."
}
}
}
class LoginResponse(BaseModel):
"""
Response model containing authentication JWT token details.
"""
access_token: str = Field(..., description="JWT access token for subsequent authenticated API requests.")
token_type: str = Field("Bearer", description="The type of the returned access token.")
expires_in: int = Field(..., description="The lifetime of the access token in seconds.")
model_config = {
"json_schema_extra": {
"example": {
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ...",
"token_type": "Bearer",
"expires_in": 3600
}
}
}
+49
View File
@@ -0,0 +1,49 @@
from uuid import UUID
from datetime import datetime
from pydantic import BaseModel, Field, HttpUrl
from typing import Optional
class CheckInRecord(BaseModel):
"""
CheckInRecord representing a successful user capture of a sculpture.
"""
sculpture_id: UUID = Field(..., description="The ID of the sculpture captured.")
unlocked_at: datetime = Field(..., description="Timestamp of when the sculpture was captured.")
checkin_photo_url: Optional[HttpUrl] = Field(None, description="URL of the photo uploaded during check-in.")
similarity_score: float = Field(
...,
description="Visual recognition similarity score between the uploaded photo and the target model.",
ge=0.0,
le=1.0
)
model_config = {
"json_schema_extra": {
"example": {
"sculpture_id": "234e5678-e89b-12d3-a456-426614174000",
"unlocked_at": "2026-05-30T10:15:30Z",
"checkin_photo_url": "https://cdn.gatos.cali.gov.co/uploads/checkin_9823.jpg",
"similarity_score": 0.92
}
}
}
class CheckInResponse(BaseModel):
"""
Response model returned after a check-in verification request.
"""
success: bool = Field(..., description="Indicates if the visual check-in met threshold requirements.")
similarity_score: float = Field(..., description="The visual similarity rating from the recognition engine.", ge=0.0, le=1.0)
unlocked_content: Optional[str] = Field(None, description="Unlocked cultural details of the sculpture, if success is true.")
reward_badge: Optional[str] = Field(None, description="Name of the badge unlocked by this capture, if any.")
model_config = {
"json_schema_extra": {
"example": {
"success": True,
"similarity_score": 0.92,
"unlocked_content": "This sculpture was crafted in tribute to the traditional festival of Macetas.",
"reward_badge": "First Sighting"
}
}
}
+60
View File
@@ -0,0 +1,60 @@
from enum import Enum
from uuid import UUID
from pydantic import BaseModel, Field, HttpUrl
from typing import Optional
class SculptureStatus(str, Enum):
ON_SITE = "on-site"
MOVED = "moved"
MISSING = "missing"
class Sculpture(BaseModel):
"""
Sculpture base model representing a public cat monument.
"""
id: UUID = Field(..., description="Unique identifier for the sculpture.")
name: str = Field(..., description="Name of the sculpture.", min_length=1)
artist: str = Field(..., description="Artist who created the sculpture.", min_length=1)
year: int = Field(..., description="Year the sculpture was created / installed.", ge=1900)
latitude: float = Field(..., description="GPS Latitude coordinate of the sculpture.", ge=-90.0, le=90.0)
longitude: float = Field(..., description="GPS Longitude coordinate of the sculpture.", ge=-180.0, le=180.0)
status: SculptureStatus = Field(..., description="Operational status of the sculpture.")
model_config = {
"json_schema_extra": {
"example": {
"id": "234e5678-e89b-12d3-a456-426614174000",
"name": "La Novia Dulce",
"artist": "Lorena Espitia",
"year": 2006,
"latitude": 3.450143,
"longitude": -76.533282,
"status": "on-site"
}
}
}
class SculptureDetails(Sculpture):
"""
Extended sculpture model containing cultural details, unlocked content, and audio resources.
"""
description: str = Field(..., description="Public cultural description of the sculpture.")
audio_url: HttpUrl = Field(..., description="Direct link to the audio guide resource.")
unlocked_content: str = Field(..., description="Extended history/curation unlocked upon checking in.")
model_config = {
"json_schema_extra": {
"example": {
"id": "234e5678-e89b-12d3-a456-426614174000",
"name": "La Novia Dulce",
"artist": "Lorena Espitia",
"year": 2006,
"latitude": 3.450143,
"longitude": -76.533282,
"status": "on-site",
"description": "Decorated with sweets and candies representing Cali's culinary traditions.",
"audio_url": "https://cdn.gatos.cali.gov.co/audio/novia_dulce.mp3",
"unlocked_content": "This sculpture was crafted in tribute to the traditional festival of Macetas."
}
}
}
+63
View File
@@ -0,0 +1,63 @@
from enum import Enum
from uuid import UUID
from datetime import datetime
from pydantic import BaseModel, Field, HttpUrl
from typing import Optional
from api.models.sculpture import SculptureStatus
class TicketStatus(str, Enum):
PENDING = "pending"
APPROVED = "approved"
REJECTED = "rejected"
class Ticket(BaseModel):
"""
Ticket model representing a crowdsourced sculpture location report.
"""
id: UUID = Field(..., description="Unique identifier for the report ticket.")
reporter_id: UUID = Field(..., description="User ID of the reporter.")
sculpture_id: UUID = Field(..., description="ID of the reported sculpture.")
latitude: float = Field(..., description="GPS Latitude reported.", ge=-90.0, le=90.0)
longitude: float = Field(..., description="GPS Longitude reported.", ge=-180.0, le=180.0)
reported_status: SculptureStatus = Field(..., description="The observed status of the sculpture.")
photo_url: Optional[HttpUrl] = Field(None, description="Verification photo of the site / pedestal.")
description: Optional[str] = Field(None, description="Additional context or details regarding the status.", max_length=500)
status: TicketStatus = Field(..., description="Resolution status of the ticket.")
created_at: datetime = Field(..., description="Timestamp of when the ticket was submitted.")
resolved_at: Optional[datetime] = Field(None, description="Timestamp of when the ticket was approved/rejected.")
notes: Optional[str] = Field(None, description="Moderator resolution comments or verification notes.", max_length=300)
model_config = {
"json_schema_extra": {
"example": {
"id": "345e6789-e89b-12d3-a456-426614174000",
"reporter_id": "123e4567-e89b-12d3-a456-426614174000",
"sculpture_id": "234e5678-e89b-12d3-a456-426614174000",
"latitude": 3.4515,
"longitude": -76.5320,
"reported_status": "moved",
"photo_url": "https://cdn.gatos.cali.gov.co/uploads/report_8321.jpg",
"description": "Under construction for street repairs. Pedestal is empty.",
"status": "pending",
"created_at": "2026-05-30T11:00:00Z",
"resolved_at": None,
"notes": None
}
}
}
class ReportVerificationRequest(BaseModel):
"""
Request model used by moderators to resolve (verify) a report ticket.
"""
status: TicketStatus = Field(..., description="New status to set for the ticket (approved or rejected).")
notes: Optional[str] = Field(None, description="Optional notes explaining the decision.", max_length=300)
model_config = {
"json_schema_extra": {
"example": {
"status": "approved",
"notes": "Verified via municipal service coordinates."
}
}
}
+33
View File
@@ -0,0 +1,33 @@
from uuid import UUID
from pydantic import BaseModel, Field, EmailStr
class User(BaseModel):
"""
User model representing an explorer in the Novias del Gato digital ecosystem.
"""
id: UUID = Field(..., description="Unique identifier for the user.")
name: str = Field(..., description="Full name of the user.", min_length=1, max_length=100)
email: EmailStr = Field(..., description="Email address of the user.")
trust_score: float = Field(
...,
description="Reputational metric scaling from 0.0 (untrusted) to 1.0 (highly reliable).",
ge=0.0,
le=1.0
)
captured_count: int = Field(
...,
description="Total number of unique sculptures verified by the user.",
ge=0
)
model_config = {
"json_schema_extra": {
"example": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Juan Perez",
"email": "juan.perez@gmail.com",
"trust_score": 0.85,
"captured_count": 12
}
}
}
+4 -1
View File
@@ -4,4 +4,7 @@ version = "0.1.0"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.14" requires-python = ">=3.14"
dependencies = [] dependencies = [
"pydantic>=2.0.0",
"email-validator>=2.0.0"
]