alabuga/backend/app/schemas/coding.py
danilgryaznev 8d51c932ce Add coding mission tables and models for programming challenges
- Introduced `coding_challenges` and `coding_attempts` tables in the database schema.
- Created corresponding SQLAlchemy models for `CodingChallenge` and `CodingAttempt`.
- Implemented service functions for evaluating coding challenges and managing user attempts.
- Added Pydantic schemas for API interactions related to coding missions.
- Updated frontend components to support coding challenges, including a new `CodingMissionPanel` for user interaction.
- Enhanced mission list and detail views to display coding challenge progress.
2025-09-29 12:11:55 -06:00

56 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Схемы для миссий с задачами на программирование."""
from __future__ import annotations
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class CodingChallengeState(BaseModel):
"""Описание шага миссии для фронтенда."""
id: int
order: int
title: str
prompt: str
starter_code: Optional[str] = None
is_passed: bool = False
is_unlocked: bool = False
last_submitted_code: Optional[str] = None
last_stdout: Optional[str] = None
last_stderr: Optional[str] = None
last_exit_code: Optional[int] = None
updated_at: Optional[datetime] = None
class CodingMissionState(BaseModel):
"""Состояние всей миссии: прогресс и список задач."""
mission_id: int
total_challenges: int
completed_challenges: int
current_challenge_id: Optional[int]
is_mission_completed: bool
challenges: list[CodingChallengeState]
class CodingRunRequest(BaseModel):
"""Запрос на запуск решения."""
code: str = Field(..., min_length=1, description="Исходный код на Python")
class CodingRunResponse(BaseModel):
"""Ответ после запуска кода пользователя."""
attempt_id: int
stdout: str
stderr: str
exit_code: int
is_passed: bool
mission_completed: bool
expected_output: Optional[str] = None