File size: 3,357 Bytes
b7a7f32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from typing import Any, Optional, List
from datetime import date
from schemas.program import ProgramInDB
from schemas.group import GroupSignInReturn, Group
from schemas.course import CourseInDB
from core.config import settings

from pydantic import BaseModel, EmailStr


# Shared properties
class UserBase(BaseModel):
    email: Optional[EmailStr] = None
    full_name: Optional[str] = None
    user_type: int
    address: str = None
    group_id: int = None
    roll: int = None
    teacher_department_id: int = None
    contact_number: str = None
    dob: date = None
    teacher_group: List[List[int]] = None
    join_year: Optional[int] = None


class UserSignUp(BaseModel):
    email: Optional[EmailStr] = None
    full_name: Optional[str] = None
    address: str = None
    group_id: int = None
    contact_number: str = None
    dob: date = None
    join_year: Optional[int] = None
    password: str


# Properties to receive via API on creation
class UserCreate(UserBase):
    email: EmailStr
    user_type: int = settings.UserType.STUDENT.value
    password: str


class AdminUserCreate(BaseModel):
    email: EmailStr = None
    full_name: str = None
    address: Optional[str] = None
    group_id: Optional[int] = None
    roll: Optional[int] = None
    contact_number: str = None
    dob: date = None
    join_year: Optional[int] = None


class VerifyUser(BaseModel):
    is_active: bool


class UserReturnMin(BaseModel):
    id: int

    class Config:
        orm_mode = True


class TeacherShort(BaseModel):
    id: int
    full_name: str
    profile_image: Optional[str]

    class Config:
        orm_mode = True


# Properties to receive via API on update
class UserUpdate(BaseModel):
    full_name: Optional[str]
    address: Optional[str]
    group_id: Optional[int]
    dob: Optional[date]
    contact_number: Optional[str]
    profile_image: Optional[str]


class PasswordUpdate(BaseModel):
    password: str


class UserInDBBase(UserBase):
    id: Optional[int] = None
    teacher_group: Optional[List[Group]]
    profile_image: Optional[str] = None

    class Config:
        orm_mode = True


# Additional properties to return via API
class User(UserInDBBase):
    pass


class GroupOfTeacherGroupOfUser(BaseModel):
    id: int
    sem: int
    program: ProgramInDB

    class Config:
        orm_mode = True


class TeacherGroupOfUser(BaseModel):
    group_id: int
    group: GroupOfTeacherGroupOfUser
    course: CourseInDB

    class Config:
        orm_mode = True


class UserReturn(BaseModel):
    id: int = None
    email: Optional[EmailStr] = None
    profile_image: Optional[str] = None
    full_name: Optional[str] = None
    address: str = None
    roll: int = None
    group: GroupSignInReturn = None
    teacher_group: List[TeacherGroupOfUser] = None
    contact_number: str = None
    dob: date = None
    user_type: int = None
    join_year: Optional[int] = None
    is_active: bool = None

    class Config:
        orm_mode = True


class UserLoginReturn(BaseModel):
    user: Optional[UserReturn]
    msg: str
    two_fa_required: Optional[bool]

    class Config:
        orm_mode = True


# Additional properties stored in DB
class UserInDB(UserInDBBase):
    hashed_password: str


class Name(BaseModel):
    id: int
    full_name: str
    profile_image: Optional[str]

    class Config:
        orm_mode = True