-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.py
53 lines (42 loc) · 1.4 KB
/
responses.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
from datetime import datetime
from typing import List, Optional
from pydantic import EmailStr, validator
from sqlmodel import SQLModel, Field
from base import CityEnum
class SessionResponse(SQLModel):
id: int
description: Optional[str] = Field(default=None)
owner: str
users: List[str]
city: CityEnum
district: Optional[str] = Field(default=None)
facility_name: str
event_date: datetime
player_limit: Optional[int] = Field(default=None)
created_at: datetime
@validator('users', pre=True)
def check_users(cls, users):
return [user.username for user in users]
class SessionResponseForUserResponse(SQLModel):
id: int
description: Optional[str] = Field(default=None)
users: List[str]
city: CityEnum
district: Optional[str] = Field(default=None)
facility_name: str
event_date: datetime
player_limit: Optional[int] = Field(default=None)
created_at: datetime
@validator('users', pre=True)
def check_users(cls, users):
return [user.username for user in users]
class UserResponse(SQLModel):
id: str
username: str
name_and_surname: str
email: EmailStr
phone_number: str
sessions: List[SessionResponseForUserResponse]
@validator('sessions', pre=True)
def check_sessions(cls, sessions):
return [SessionResponseForUserResponse(users=session.users, **session.dict()) for session in sessions]