File size: 2,366 Bytes
6e8d513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Pydantic models for user endpoints"""

from pydantic import BaseModel, Field, ConfigDict
from typing import Optional
from datetime import datetime


class UserRegisterRequest(BaseModel):
    """Request model for user registration"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "unique_id": "550e8400-e29b-41d4-a716-446655440000",
                "name": "John Doe"
            }
        }
    )
    
    unique_id: str = Field(
        ..., min_length=1, max_length=255,
        description="Browser-generated unique identifier (stored in localStorage)"
    )
    name: Optional[str] = Field(
        None, min_length=1, max_length=100,
        description="User's display name (optional, will generate random if not provided)"
    )


class UserResponse(BaseModel):
    """Response model for user data"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "id": "123e4567-e89b-12d3-a456-426614174000",
                "unique_id": "550e8400-e29b-41d4-a716-446655440000",
                "name": "John Doe",
                "created_at": "2024-01-01T12:00:00Z",
                "updated_at": "2024-01-01T12:00:00Z"
            }
        }
    )
    
    id: str = Field(..., description="User UUID")
    unique_id: str = Field(..., description="Browser-generated unique identifier")
    name: str = Field(..., description="User's display name")
    created_at: str = Field(..., description="User creation timestamp")
    updated_at: str = Field(..., description="User last update timestamp")


class UserUpdateNameRequest(BaseModel):
    """Request model for updating user name"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "name": "Jane Doe"
            }
        }
    )
    
    name: str = Field(
        ..., min_length=1, max_length=100,
        description="New display name"
    )


class UserGetRequest(BaseModel):
    """Request model for getting user by unique_id"""
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "unique_id": "550e8400-e29b-41d4-a716-446655440000"
            }
        }
    )
    
    unique_id: str = Field(
        ..., min_length=1, max_length=255,
        description="Browser-generated unique identifier"
    )