migrate to opus-magnum app
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
from ninja import Schema, ModelSchema
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from .models import (
|
||||
Submission,
|
||||
PuzzleResponse,
|
||||
SubmissionFile,
|
||||
SteamCollectionItem,
|
||||
SteamCollection,
|
||||
)
|
||||
|
||||
|
||||
# Input Schemas
|
||||
class SubmissionFileIn(Schema):
|
||||
"""Schema for file upload data"""
|
||||
|
||||
original_filename: str
|
||||
content_type: str
|
||||
ocr_data: Optional[dict] = None
|
||||
|
||||
|
||||
class PuzzleResponseIn(Schema):
|
||||
"""Schema for creating a puzzle response"""
|
||||
|
||||
puzzle_id: int
|
||||
puzzle_name: str
|
||||
cost: Optional[int] = None
|
||||
cycles: Optional[int] = None
|
||||
area: Optional[int] = None
|
||||
needs_manual_validation: bool = False
|
||||
ocr_confidence_cost: Optional[float] = None
|
||||
ocr_confidence_cycles: Optional[float] = None
|
||||
ocr_confidence_area: Optional[float] = None
|
||||
|
||||
|
||||
class SubmissionIn(Schema):
|
||||
"""Schema for creating a submission"""
|
||||
|
||||
notes: Optional[str] = None
|
||||
manual_validation_requested: bool = False
|
||||
responses: List[PuzzleResponseIn]
|
||||
|
||||
|
||||
# Output Schemas
|
||||
class SubmissionFileOut(ModelSchema):
|
||||
"""Schema for submission file output"""
|
||||
|
||||
file_url: Optional[str]
|
||||
|
||||
class Meta:
|
||||
model = SubmissionFile
|
||||
fields = [
|
||||
"id",
|
||||
"original_filename",
|
||||
"file_size",
|
||||
"content_type",
|
||||
"ocr_processed",
|
||||
"ocr_raw_data",
|
||||
"ocr_error",
|
||||
"created_at",
|
||||
]
|
||||
|
||||
|
||||
class PuzzleResponseOut(ModelSchema):
|
||||
"""Schema for puzzle response output"""
|
||||
|
||||
files: List[SubmissionFileOut]
|
||||
final_cost: Optional[int]
|
||||
final_cycles: Optional[int]
|
||||
final_area: Optional[int]
|
||||
|
||||
class Meta:
|
||||
model = PuzzleResponse
|
||||
fields = [
|
||||
"id",
|
||||
"puzzle",
|
||||
"puzzle_name",
|
||||
"cost",
|
||||
"cycles",
|
||||
"area",
|
||||
"needs_manual_validation",
|
||||
"ocr_confidence_cost",
|
||||
"ocr_confidence_cycles",
|
||||
"ocr_confidence_area",
|
||||
"validated_cost",
|
||||
"validated_cycles",
|
||||
"validated_area",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SubmissionOut(ModelSchema):
|
||||
"""Schema for submission output"""
|
||||
|
||||
responses: List[PuzzleResponseOut]
|
||||
total_responses: int
|
||||
needs_validation: bool
|
||||
|
||||
class Meta:
|
||||
model = Submission
|
||||
fields = [
|
||||
"id",
|
||||
"user",
|
||||
"notes",
|
||||
"is_validated",
|
||||
"validated_by",
|
||||
"validated_at",
|
||||
"manual_validation_requested",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SubmissionListOut(Schema):
|
||||
"""Schema for submission list output"""
|
||||
|
||||
id: UUID
|
||||
# user: int
|
||||
notes: Optional[str]
|
||||
total_responses: int
|
||||
needs_validation: bool
|
||||
is_validated: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Validation Schemas
|
||||
class ValidationIn(Schema):
|
||||
"""Schema for manual validation input"""
|
||||
|
||||
puzzle: Optional[int] = None
|
||||
validated_cost: Optional[int] = None
|
||||
validated_cycles: Optional[int] = None
|
||||
validated_area: Optional[int] = None
|
||||
|
||||
|
||||
# Collection Schemas
|
||||
class PuzzlePointsFactorOut(Schema):
|
||||
"""Schema for puzzle points factor output"""
|
||||
|
||||
cost: int
|
||||
cycles: int
|
||||
area: int
|
||||
|
||||
|
||||
class SteamCollectionOut(ModelSchema):
|
||||
"""Schema for Steam collection output"""
|
||||
|
||||
class Meta:
|
||||
model = SteamCollection
|
||||
fields = [
|
||||
"id",
|
||||
"steam_id",
|
||||
"title",
|
||||
"description",
|
||||
"author_name",
|
||||
"total_items",
|
||||
"unique_visitors",
|
||||
"current_favorites",
|
||||
"accepting_submissions",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SteamCollectionItemOut(ModelSchema):
|
||||
"""Schema for Steam collection item output"""
|
||||
|
||||
steam_url: str
|
||||
points_factor: Optional[PuzzlePointsFactorOut] = None
|
||||
|
||||
class Meta:
|
||||
model = SteamCollectionItem
|
||||
fields = [
|
||||
"id",
|
||||
"steam_item_id",
|
||||
"title",
|
||||
"author_name",
|
||||
"description",
|
||||
"tags",
|
||||
"order_index",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def resolve_points_factor(obj) -> Optional[PuzzlePointsFactorOut]:
|
||||
if obj.points_factor:
|
||||
return PuzzlePointsFactorOut(
|
||||
cost=obj.points_factor.cost,
|
||||
cycles=obj.points_factor.cycles,
|
||||
area=obj.points_factor.area,
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
# Error Schemas
|
||||
class ErrorOut(Schema):
|
||||
"""Schema for error responses"""
|
||||
|
||||
detail: str
|
||||
code: Optional[str] = None
|
||||
|
||||
|
||||
class ValidationErrorOut(Schema):
|
||||
"""Schema for validation error responses"""
|
||||
|
||||
detail: str
|
||||
errors: dict
|
||||
|
||||
|
||||
# User Schemas
|
||||
class UserInfoOut(Schema):
|
||||
"""Schema for user information output"""
|
||||
|
||||
id: Optional[int] = None
|
||||
username: Optional[str] = None
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
points: int = 0
|
||||
is_authenticated: bool
|
||||
is_staff: bool
|
||||
is_superuser: bool
|
||||
cas_groups: Optional[List[str]] = None
|
||||
Reference in New Issue
Block a user