File size: 1,619 Bytes
ca76540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from sqlmodel import SQLModel, Field, Relationship
from typing import Optional, List
import uuid
from datetime import datetime


class UserBase(SQLModel):
    email: str = Field(unique=True, nullable=False, max_length=255, description="User's email address")


class User(UserBase, table=True):
    """
    User model representing a registered user in the system.
    """
    __tablename__ = "users"

    id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True, description="Unique identifier for the user")
    email: str = Field(unique=True, nullable=False, max_length=255, description="User's email address")
    hashed_password: str = Field(nullable=False, description="Hashed password for authentication")
    created_at: datetime = Field(default_factory=datetime.utcnow, description="Timestamp when user was created")
    updated_at: datetime = Field(default_factory=datetime.utcnow, description="Timestamp when user was last updated")


    class Config:
        arbitrary_types_allowed = True


class UserCreate(UserBase):
    """
    Schema for creating a new user.
    """
    password: str

    class Config:
        # Prevent extra fields from being passed
        extra = "forbid"


class UserUpdate(SQLModel):
    """
    Schema for updating user information.
    """
    email: Optional[str] = None


class UserRead(UserBase):
    """
    Schema for reading user information (without sensitive data).
    """
    id: uuid.UUID
    created_at: datetime
    updated_at: datetime


class UserLogin(SQLModel):
    """
    Schema for user login credentials.
    """
    email: str
    password: str