service_man/api/models/user_model.py

30 lines
700 B
Python
Raw Normal View History

2024-03-06 02:28:59 +03:00
from sqlalchemy import Boolean, Column, String
2024-03-06 03:59:16 +03:00
from sqlalchemy.orm import Mapped
2024-03-11 21:07:01 +03:00
from api.schemas import UserReadDTO
2024-03-04 07:12:29 +03:00
2024-03-11 21:07:01 +03:00
from . import Base
2024-03-04 07:12:29 +03:00
2024-03-11 21:07:01 +03:00
class UserModel(Base):
2024-03-04 07:12:29 +03:00
__tablename__ = "users"
2024-03-06 03:59:16 +03:00
name: Mapped[str]
2024-03-04 07:12:29 +03:00
email = Column(String, unique=True)
hashed_password = Column(String)
is_active = Column(Boolean, default=True)
def __repr__(self):
return (
f"<User(id={self.id}, "
f'email="{self.email}", '
f'hashed_password="{self.hashed_password}", '
f"is_active={self.is_active})>"
)
2024-03-06 03:59:16 +03:00
2024-03-11 21:07:01 +03:00
def to_read_model(self) -> UserReadDTO:
return UserReadDTO(
2024-03-06 03:59:16 +03:00
id=self.id,
name=self.name,
)