new features
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Select, select
|
||||
from sqlalchemy import Select, or_, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from cpv3.modules.projects.models import Project
|
||||
@@ -16,13 +16,31 @@ class ProjectRepository:
|
||||
def __init__(self, session: AsyncSession) -> None:
|
||||
self._session = session
|
||||
|
||||
async def list_all(self, *, requester: User) -> list[Project]:
|
||||
async def list_all(
|
||||
self,
|
||||
*,
|
||||
requester: User,
|
||||
search: str | None = None,
|
||||
status: str | None = None,
|
||||
) -> list[Project]:
|
||||
stmt: Select[tuple[Project]] = select(Project).where(
|
||||
Project.is_active.is_(True)
|
||||
)
|
||||
if not requester.is_staff:
|
||||
stmt = stmt.where(Project.owner_id == requester.id)
|
||||
|
||||
if search:
|
||||
pattern = f"%{search}%"
|
||||
stmt = stmt.where(
|
||||
or_(
|
||||
Project.name.ilike(pattern),
|
||||
Project.description.ilike(pattern),
|
||||
)
|
||||
)
|
||||
|
||||
if status:
|
||||
stmt = stmt.where(Project.status == status)
|
||||
|
||||
result = await self._session.execute(stmt.order_by(Project.created_at.desc()))
|
||||
return list(result.scalars().all())
|
||||
|
||||
@@ -34,14 +52,16 @@ class ProjectRepository:
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
async def create(self, *, requester: User, data: ProjectCreate) -> Project:
|
||||
async def create(
|
||||
self, *, requester: User, data: ProjectCreate, folder: str, status: str,
|
||||
) -> Project:
|
||||
project = Project(
|
||||
owner_id=requester.id,
|
||||
name=data.name,
|
||||
description=data.description,
|
||||
language=data.language,
|
||||
folder=data.folder,
|
||||
status=data.status,
|
||||
folder=folder,
|
||||
status=status,
|
||||
)
|
||||
|
||||
self._session.add(project)
|
||||
|
||||
Reference in New Issue
Block a user