Skip to content

models

This module is concerned with creating models used for both table creation and data validation.

The classes with table=True are used to define tables that will be created in the database.

The rest of the classes are used for schema validation: They are used to control what data the api endpoints can receive and return. If the data doesn't match the schema at either end of the api journey then an error will occur.

Note : Plain SQLModels effectively act as Pydantic Models

UserBase

Bases: SQLModel

Represents the base attributes of a user.

Attributes:

Name Type Description
email EmailStr

The email address of the user. It should be unique.

Source code in api/core/models.py
19
20
21
22
23
24
25
26
27
28
29
30
class UserBase(SQLModel):
    """
    Represents the base attributes of a user.

    Attributes
    ----------
    email : EmailStr
        The email address of the user. It should be unique.

    """

    email: EmailStr = Field(unique=True, index=True, sa_type=AutoString)

User

Bases: UserBase

Represents a user entity, inheriting from UserBase.

Attributes:

Name Type Description
id Optional[int]

The unique identifier of the user. It is a primary key.

password str

The hashed password of the user.

created_at Optional[datetime]

The datetime when the user account was created. Defaults to the current UTC time.

Source code in api/core/models.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class User(UserBase, table=True):  # type: ignore
    """
    Represents a user entity, inheriting from UserBase.

    Attributes
    ----------
    id : Optional[int]
        The unique identifier of the user. It is a primary key.
    password : str
        The hashed password of the user.
    created_at : Optional[datetime]
        The datetime when the user account was created. Defaults to the current UTC time.

    """

    id: Optional[int] = Field(default=None, primary_key=True)
    password: str
    created_at: Optional[datetime] = Field(default_factory=datetime.utcnow, nullable=False)

UserCreate

Bases: UserBase

Represents the data required to create a new user.

Attributes:

Name Type Description
email EmailStr

The email address of the user. It should be unique.

password str

The plaintext password of the user.

Source code in api/core/models.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class UserCreate(UserBase):
    """
    Represents the data required to create a new user.

    Attributes
    ----------
    email : EmailStr
        The email address of the user. It should be unique.
    password : str
        The plaintext password of the user.

    """

    password: str

UserRead

Bases: UserBase

Represents the data of a user to be read.

Attributes:

Name Type Description
email EmailStr

The email address of the user. It should be unique.

created_at datetime

The datetime when the user account was created.

Source code in api/core/models.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class UserRead(UserBase):
    """
    Represents the data of a user to be read.

    Attributes
    ----------
    email : EmailStr
        The email address of the user. It should be unique.
    created_at : datetime
        The datetime when the user account was created.

    """

    created_at: datetime

UserLogin

Bases: UserCreate

Represents the data required for user login, inheriting from UserCreate.

Attributes:

Name Type Description
email EmailStr

The email address of the user. It should be unique.

password str

The plaintext password of the user.

Source code in api/core/models.py
85
86
87
88
89
90
91
92
93
94
95
96
class UserLogin(UserCreate):
    """
    Represents the data required for user login, inheriting from UserCreate.

    Attributes
    ----------
    email : EmailStr
        The email address of the user. It should be unique.
    password : str
        The plaintext password of the user.

    """

Token

Bases: SQLModel

Represents a token entity returned when a user requests one.

Attributes:

Name Type Description
access_token str

The access token string.

token_type str

The type of the token.

Source code in api/core/models.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class Token(SQLModel):
    """
    Represents a token entity returned when a user requests one.

    Attributes
    ----------
    access_token : str
        The access token string.
    token_type : str
        The type of the token.

    """

    access_token: str
    token_type: str

HealthCheck

Bases: BaseModel

Response model to validate and return when performing a health check.

Attributes:

Name Type Description
status str

The status of the health check. Default value is "OK".

Source code in api/core/models.py
116
117
118
119
120
121
122
123
124
125
126
127
class HealthCheck(BaseModel):
    """
    Response model to validate and return when performing a health check.

    Attributes
    ----------
    status : str
        The status of the health check. Default value is "OK".

    """

    status: str = "OK"

UploadedFile

Bases: BaseModel

Response model to return when file is uploaded.

Attributes:

Name Type Description
filename str

The name of the uploaded file.

size int

The size of the uploaded file.

content_type str

The content type of the uploaded file.

status str

The status of the uploaded file.

Source code in api/core/models.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class UploadedFile(BaseModel):
    """
    Response model to return when file is uploaded.

    Attributes
    ----------
    filename : str
        The name of the uploaded file.
    size : int
        The size of the uploaded file.
    content_type : str
        The content type of the uploaded file.
    status : str
        The status of the uploaded file.

    """

    filename: str
    size: int
    content_type: str
    status: str