File size: 2,733 Bytes
0225ffc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from pydantic import BaseModel, Field
from typing import Optional, List

class UpdateCodingSchema(BaseModel):
    """
    Schema for updating a user's coding statistics and history.
    Used by the frontend to update solved question counters and history arrays.
    """
    recently_solved: Optional[List[int]] = Field(
        None, 
        description="List of unique question IDs that were recently solved by the user, ordered by recency.",
        example=[101, 102]
    )
    recently_visited: Optional[List[int]] = Field(
        None, 
        description="List of unique question IDs recently visited or viewed by the user.",
        example=[103, 104]
    )
    all_questions_solved: Optional[List[int]] = Field(
        None, 
        description="Historical list of all unique question IDs successfully solved by the user.",
        example=[101, 102, 105]
    )
    easy: Optional[int] = Field(
        None, 
        description="Total number of 'easy' difficulty coding questions solved.",
        example=5
    )
    medium: Optional[int] = Field(
        None, 
        description="Total number of 'medium' difficulty coding questions solved.",
        example=2
    )
    hard: Optional[int] = Field(
        None, 
        description="Total number of 'hard' difficulty coding questions solved.",
        example=0
    )

    class Config:
        json_schema_extra = {
            "example": {
                "recently_solved": [101, 102],
                "recently_visited": [101, 102, 103],
                "all_questions_solved": [101, 102],
                "easy": 5,
                "medium": 2,
                "hard": 0
            }
        }


class RunCode(BaseModel):
    """
    Schema representing user code execution requests.
    Sent when the user compiles or submits code for a specific problem.
    """
    language: str = Field(
        ..., 
        description="Programming language used for code execution. Currently supports 'python'.",
        example="python"
    )
    code: str = Field(
        ..., 
        description="Raw code string written by the user to be executed against test cases.",
        example="def add(a, b):\n    return a + b"
    )
    question_id: int = Field(
        ..., 
        description="The database identifier of the problem being solved.",
        example=1
    )

    class Config:
        json_schema_extra = {
            "example": {
                "language": "python",
                "code": "def twoSum(nums, target):\n    seen = {}\n    for i, num in enumerate(nums):\n        if target - num in seen:\n            return [seen[target - num], i]\n        seen[num] = i\n    return []",
                "question_id": 1
            }
        }