uow and di basic implementation
This commit is contained in:
7
api/models/__init__.py
Normal file
7
api/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from .base import Base
|
||||
from .user import User
|
||||
|
||||
__all__ = (
|
||||
"Base",
|
||||
"User",
|
||||
)
|
12
api/models/base.py
Normal file
12
api/models/base.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
)
|
29
api/models/user.py
Normal file
29
api/models/user.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from sqlalchemy import Boolean, Column, String
|
||||
from sqlalchemy.orm import Mapped
|
||||
|
||||
from api.schemas.user_schema import UserSchema
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
name: Mapped[str]
|
||||
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})>"
|
||||
)
|
||||
|
||||
def to_read_model(self) -> UserSchema:
|
||||
return UserSchema(
|
||||
id=self.id,
|
||||
name=self.name,
|
||||
)
|
Reference in New Issue
Block a user