aef8791151
- Added Appshell component with responsive navbar and main content area - Integrated ColorSchemeToggle for light/dark mode switching - Created Welcome component with styled title and introductory text - Developed ChatPage for LLM interaction with WebSocket support - Implemented Biblioteca for managing notes with rich text editor - Added LoginPage for user authentication with error handling - Introduced MessageList and MessageBubble components for chat messages - Styled components with CSS modules for consistent design
83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean
|
|
from domains.ArquitectureLayer.Model import Model_base
|
|
from domains.ArquitectureLayer.Mapper import Mapper_base
|
|
from domains.ArquitectureLayer.Repo import Repo_base
|
|
from domains.Usuario.usuario import Usuario
|
|
|
|
# ----------------------
|
|
# MODELO (SQLAlchemy)
|
|
# ----------------------
|
|
|
|
class UsuarioModel(Model_base):
|
|
__tablename__ = 'usuarios'
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
nombre = Column(String, nullable=False)
|
|
email = Column(String, unique=True, nullable=False)
|
|
activo = Column(Boolean, default=True, nullable=False)
|
|
|
|
# ----------------------
|
|
# MAPPER
|
|
# ----------------------
|
|
|
|
class UsuarioMapper(Mapper_base[Usuario, UsuarioModel]):
|
|
@staticmethod
|
|
def to_model(obj: Usuario) -> UsuarioModel:
|
|
return UsuarioModel(
|
|
id=obj.id,
|
|
nombre=obj.nombre,
|
|
email=obj.email,
|
|
activo=obj.activo
|
|
)
|
|
|
|
@staticmethod
|
|
def from_model(model: UsuarioModel) -> Usuario:
|
|
return Usuario(
|
|
id=model.id,
|
|
nombre=model.nombre,
|
|
email=model.email,
|
|
activo=model.activo
|
|
)
|
|
|
|
@staticmethod
|
|
def to_dict(obj: Usuario) -> dict:
|
|
return {
|
|
'id': obj.id,
|
|
'nombre': obj.nombre,
|
|
'email': obj.email,
|
|
'activo': obj.activo
|
|
}
|
|
|
|
@staticmethod
|
|
def from_dict(data: dict) -> Usuario:
|
|
return Usuario(
|
|
id=data['id'],
|
|
nombre=data['nombre'],
|
|
email=data['email'],
|
|
activo=data.get('activo', True)
|
|
)
|
|
|
|
@staticmethod
|
|
def from_model_list(models: list[UsuarioModel]) -> list[Usuario]:
|
|
return [UsuarioMapper.from_model(m) for m in models]
|
|
|
|
# ----------------------
|
|
# REPO
|
|
# ----------------------
|
|
|
|
class UsuarioRepo(Repo_base[UsuarioModel, Usuario]):
|
|
def __init__(self, session):
|
|
super().__init__(
|
|
session=session,
|
|
modelo=UsuarioModel,
|
|
mapper=UsuarioMapper
|
|
)
|
|
|
|
def get_by_email(self, email: str) -> Usuario | None:
|
|
model = (
|
|
self.session.query(self.Modelo)
|
|
.filter_by(email=email, sys_deleted_at=None)
|
|
.first()
|
|
)
|
|
return self.Mapper.from_model(model) if model else None
|