-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.py
72 lines (51 loc) · 1.7 KB
/
users.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
__all__ = ["CreateUser", "ViewUser", "UpdateUser", "ViewUserScheduleKey"]
from typing import Optional, Collection
from pydantic import Field, BaseModel, field_validator, ConfigDict
from src.schemas.linked import LinkedCalendarView
class CreateUser(BaseModel):
"""
Represents a user instance to be created.
"""
id: Optional[int] = None
email: str
name: Optional[str] = None
class ViewUser(BaseModel):
"""
Represents a user instance from the database excluding sensitive information.
"""
id: int
email: str
name: Optional[str] = None
favorites_association: list["UserXFavoriteGroupView"] = Field(default_factory=list)
linked_calendars: dict[str, "LinkedCalendarView"] = Field(default_factory=dict)
music_room_hidden: bool
sports_hidden: bool
moodle_hidden: bool
@field_validator("favorites_association", mode="before")
def groups_to_list(cls, v):
if isinstance(v, Collection):
v = list(v)
return v
@field_validator("linked_calendars", mode="before")
def calendars_to_dict(cls, v):
if not isinstance(v, dict):
keys = [calendar.alias for calendar in v]
return dict(zip(keys, v))
return v
model_config = ConfigDict(from_attributes=True)
class ViewUserScheduleKey(BaseModel):
"""
Represents a user schedule key.
"""
user_id: int
access_key: str
resource_path: str
class UpdateUser(BaseModel):
"""
Represents a user instance to be updated.
"""
email: Optional[str] = None
name: Optional[str] = None
# fix circular import
from src.schemas.event_groups import UserXFavoriteGroupView # noqa: E402
ViewUser.update_forward_refs()