Commit existing codebase
This commit is contained in:
commit
49bc902bb9
24 changed files with 1208 additions and 0 deletions
60
app/user/dto.py
Normal file
60
app/user/dto.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import calendar
|
||||
from datetime import datetime, date
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.user.model import User, Sex
|
||||
|
||||
|
||||
class UserCreationModel(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
password: str
|
||||
given_name: str
|
||||
family_name: Optional[str]
|
||||
sex: str
|
||||
birthdate: Optional[int]
|
||||
|
||||
def to_entity(self) -> User:
|
||||
birthdate = None
|
||||
|
||||
if self.birthdate is not None:
|
||||
birthdate = date.fromtimestamp(self.birthdate)
|
||||
|
||||
return User(
|
||||
username=self.username,
|
||||
email=self.email,
|
||||
password=self.password,
|
||||
given_name=self.given_name,
|
||||
family_name=self.family_name,
|
||||
sex=Sex[self.sex],
|
||||
birthdate=birthdate
|
||||
)
|
||||
|
||||
|
||||
class UserResourceModel(BaseModel):
|
||||
id: int
|
||||
username: str
|
||||
email: str
|
||||
given_name: str
|
||||
family_name: Optional[str]
|
||||
sex: str
|
||||
birthdate: Optional[int]
|
||||
|
||||
@staticmethod
|
||||
def from_entity(user: User):
|
||||
birthdate = None
|
||||
|
||||
if user.birthdate is not None:
|
||||
birthdate = calendar.timegm(user.birthdate.timetuple())
|
||||
|
||||
return UserResourceModel(
|
||||
id=user.id,
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
given_name=user.given_name,
|
||||
family_name=user.family_name,
|
||||
sex=user.sex.name,
|
||||
birthdate=birthdate
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue