-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.py
84 lines (61 loc) · 2.14 KB
/
schemas.py
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
from pydantic import BaseModel, Field, validator, EmailStr
from datetime import datetime
from typing import Optional, Literal, Generic, TypeVar
T = TypeVar('T')
class DateTimeBase(BaseModel):
created_at: str
updated_at: str
@validator("created_at", "updated_at", pre=True)
def datetime_to_str(cls, v: datetime):
if isinstance(v, datetime):
return datetime.strftime(v, "%Y-%m-%d %H:%M:%S")
return str(v)
class PaginatedResponse(BaseModel, Generic[T]):
total_count: int
total_pages: int
current_page: int
data: list[T]
class User(DateTimeBase):
id: int
name: str
account: str
password: str
email: str
phone: str
role: str
class Config:
from_attributes = True
class UserCreateInput(BaseModel):
name: str = Field(max_length=30, title="User name")
account: str = Field(max_length=100, title="Account")
password: str = Field(max_length=64, title="Password")
email: EmailStr
phone: str = Field(max_length=20, title="Phone Number")
role: Literal["Employee", "HR"] = Field(default="Employee")
class UserUpdateInput(BaseModel):
name: Optional[str] = Field(max_length=30, title="User name")
account: Optional[str] = Field(max_length=100, title="Account")
password: Optional[str] = Field(max_length=64, title="Password")
email: Optional[EmailStr]
phone: Optional[str] = Field(max_length=20, title="Phone Number")
role: Optional[Literal["Employee", "HR"]] = None
class LoginInput(BaseModel):
account: Optional[str] = Field(max_length=100, title="Account")
password: Optional[str] = Field(max_length=30, title="Password")
class LoginReturn(User):
token: str
class AttendanceRecord(DateTimeBase):
id: int
attendance_date: datetime
time_in: datetime
time_out: Optional[datetime] = None
attendance_type: str
user_id: int
user: User
class Config:
from_attributes = True
class AttendanceRecordUpdateInput(BaseModel):
attendance_date: Optional[datetime] = None
time_in: Optional[datetime] = None
time_out: Optional[datetime] = None
attendance_type: Optional[str] = None