35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from sqlalchemy.orm import Session
|
|
|
|
from packages.adapters.sqlalchemy_impl.models import ProjectModel
|
|
from packages.domain import Project
|
|
|
|
|
|
class SQLAlchemyProjectRepository:
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def list_by_workspace(self, workspace_id: str) -> list[Project]:
|
|
models = self.session.query(ProjectModel).filter(ProjectModel.workspace_id == workspace_id).all()
|
|
return [
|
|
Project(
|
|
id=model.id,
|
|
workspace_id=model.workspace_id,
|
|
name=model.name,
|
|
description=model.description,
|
|
created_at=model.created_at,
|
|
)
|
|
for model in models
|
|
]
|
|
|
|
def create(self, project: Project) -> Project:
|
|
model = ProjectModel(
|
|
id=project.id,
|
|
workspace_id=project.workspace_id,
|
|
name=project.name,
|
|
description=project.description,
|
|
created_at=project.created_at,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
return project
|