Spaces:
Runtime error
Runtime error
New commit
Browse files- src/models.py +33 -2
src/models.py
CHANGED
|
@@ -112,11 +112,17 @@ class PendingTagLink(Base):
|
|
| 112 |
"""Database model for pending tag link requests."""
|
| 113 |
__tablename__ = "pending_tag_links"
|
| 114 |
id = Column(Integer, primary_key=True, index=True)
|
| 115 |
-
|
| 116 |
-
target_user_id = Column(String, nullable=False)
|
| 117 |
target_user_type = Column(SQLAlchemyEnum(TargetUserType), nullable=False)
|
|
|
|
| 118 |
initiated_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
| 119 |
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
class DeviceLog(Base):
|
|
@@ -256,6 +262,31 @@ class PrepareDeviceRequest(BaseModel):
|
|
| 256 |
user_id_str: str # Can be student_id or username
|
| 257 |
user_type: UserTypeEnum
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
# --- New RFID Models ---
|
| 260 |
class RfidScanRequest(BaseModel):
|
| 261 |
"""Request body for the unified RFID scan endpoint."""
|
|
|
|
| 112 |
"""Database model for pending tag link requests."""
|
| 113 |
__tablename__ = "pending_tag_links"
|
| 114 |
id = Column(Integer, primary_key=True, index=True)
|
| 115 |
+
device_id_fk = Column(Integer, ForeignKey("devices.id"), nullable=False)
|
|
|
|
| 116 |
target_user_type = Column(SQLAlchemyEnum(TargetUserType), nullable=False)
|
| 117 |
+
target_identifier = Column(String, nullable=False)
|
| 118 |
initiated_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
| 119 |
+
expires_at = Column(DateTime, nullable=False)
|
| 120 |
created_at = Column(DateTime, default=datetime.utcnow)
|
| 121 |
+
|
| 122 |
+
# Relationships
|
| 123 |
+
device = relationship("Device", foreign_keys=[device_id_fk])
|
| 124 |
+
initiated_by = relationship("User", foreign_keys=[initiated_by_user_id])
|
| 125 |
+
|
| 126 |
|
| 127 |
|
| 128 |
class DeviceLog(Base):
|
|
|
|
| 262 |
user_id_str: str # Can be student_id or username
|
| 263 |
user_type: UserTypeEnum
|
| 264 |
|
| 265 |
+
|
| 266 |
+
class PrepareTagLinkRequest(BaseModel):
|
| 267 |
+
"""Request to prepare a device for tag linking."""
|
| 268 |
+
device_identifier: str = Field(..., description="The device ID that will scan for tags")
|
| 269 |
+
target_user_type: TargetUserType = Field(..., description="Type of user (STUDENT or STAFF_ADMIN)")
|
| 270 |
+
target_identifier: str = Field(..., description="Student ID or username to link the tag to")
|
| 271 |
+
|
| 272 |
+
class PendingTagLinkResponse(BaseModel):
|
| 273 |
+
"""Response model for pending tag link information."""
|
| 274 |
+
id: int
|
| 275 |
+
device_id_fk: int
|
| 276 |
+
target_user_type: TargetUserType
|
| 277 |
+
target_identifier: str
|
| 278 |
+
initiated_by_user_id: int
|
| 279 |
+
expires_at: datetime
|
| 280 |
+
created_at: datetime
|
| 281 |
+
|
| 282 |
+
class Config:
|
| 283 |
+
from_attributes = True
|
| 284 |
+
|
| 285 |
+
class ScannedTagSubmit(BaseModel):
|
| 286 |
+
"""Request when submitting a scanned tag for linking."""
|
| 287 |
+
scanned_tag_id: str = Field(..., description="The scanned RFID tag ID")
|
| 288 |
+
|
| 289 |
+
|
| 290 |
# --- New RFID Models ---
|
| 291 |
class RfidScanRequest(BaseModel):
|
| 292 |
"""Request body for the unified RFID scan endpoint."""
|