Files
game-marathon/backend/app/schemas/game.py

94 lines
2.9 KiB
Python
Raw Normal View History

2025-12-14 02:38:35 +07:00
from datetime import datetime
from typing import Self
from pydantic import BaseModel, Field, model_validator
2025-12-14 02:38:35 +07:00
from app.models.game import GameType
from app.models.challenge import ProofType
2025-12-14 02:38:35 +07:00
from app.schemas.user import UserPublic
class GameBase(BaseModel):
title: str = Field(..., min_length=1, max_length=100)
download_url: str = Field(..., min_length=1)
genre: str | None = Field(None, max_length=50)
class GameCreate(GameBase):
cover_url: str | None = None
# Тип игры
game_type: GameType = GameType.CHALLENGES
# Поля для типа "Прохождение"
2026-01-09 19:02:08 +07:00
playthrough_points: int | None = Field(None, ge=1)
playthrough_description: str | None = None
playthrough_proof_type: ProofType | None = None
playthrough_proof_hint: str | None = None
@model_validator(mode='after')
def validate_playthrough_fields(self) -> Self:
if self.game_type == GameType.PLAYTHROUGH:
if self.playthrough_points is None:
raise ValueError('playthrough_points обязателен для типа "Прохождение"')
if self.playthrough_description is None:
raise ValueError('playthrough_description обязателен для типа "Прохождение"')
if self.playthrough_proof_type is None:
raise ValueError('playthrough_proof_type обязателен для типа "Прохождение"')
return self
2025-12-14 02:38:35 +07:00
class GameUpdate(BaseModel):
title: str | None = Field(None, min_length=1, max_length=100)
download_url: str | None = None
genre: str | None = None
# Тип игры
game_type: GameType | None = None
# Поля для типа "Прохождение"
2026-01-09 19:02:08 +07:00
playthrough_points: int | None = Field(None, ge=1)
playthrough_description: str | None = None
playthrough_proof_type: ProofType | None = None
playthrough_proof_hint: str | None = None
2025-12-14 02:38:35 +07:00
class GameShort(BaseModel):
id: int
title: str
cover_url: str | None = None
2026-01-03 00:12:07 +07:00
download_url: str
game_type: str = "challenges"
2025-12-14 02:38:35 +07:00
class Config:
from_attributes = True
class GameResponse(GameBase):
id: int
cover_url: str | None = None
2025-12-14 20:21:56 +07:00
status: str = "pending"
proposed_by: UserPublic | None = None
approved_by: UserPublic | None = None
2025-12-14 02:38:35 +07:00
challenges_count: int = 0
created_at: datetime
# Тип игры
game_type: str = "challenges"
# Поля для типа "Прохождение"
playthrough_points: int | None = None
playthrough_description: str | None = None
playthrough_proof_type: str | None = None
playthrough_proof_hint: str | None = None
2025-12-14 02:38:35 +07:00
class Config:
from_attributes = True
class PlaythroughInfo(BaseModel):
"""Информация о прохождении для игр типа playthrough"""
description: str | None = None
points: int | None = None
proof_type: str | None = None
proof_hint: str | None = None