chore: claude final touches
This commit is contained in:
@@ -35,6 +35,31 @@ class JobRepository:
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
async def list_active_by_type(
|
||||
self,
|
||||
*,
|
||||
requester: User,
|
||||
job_type: str,
|
||||
project_id: uuid.UUID | None,
|
||||
statuses: tuple[str, ...],
|
||||
) -> list[Job]:
|
||||
stmt: Select[tuple[Job]] = (
|
||||
select(Job)
|
||||
.where(Job.is_active.is_(True))
|
||||
.where(Job.user_id == requester.id)
|
||||
.where(Job.job_type == job_type)
|
||||
.where(Job.status.in_(statuses))
|
||||
.order_by(Job.created_at.desc())
|
||||
)
|
||||
|
||||
if project_id is None:
|
||||
stmt = stmt.where(Job.project_id.is_(None))
|
||||
else:
|
||||
stmt = stmt.where(Job.project_id == project_id)
|
||||
|
||||
result = await self._session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def create(self, *, requester: User, data: JobCreate) -> Job:
|
||||
job = Job(
|
||||
user_id=requester.id,
|
||||
|
||||
@@ -16,6 +16,7 @@ from cpv3.modules.jobs.schemas import (
|
||||
JobUpdate,
|
||||
)
|
||||
from cpv3.modules.jobs.service import JobService
|
||||
from cpv3.modules.tasks.service import TaskService
|
||||
from cpv3.modules.users.models import User
|
||||
|
||||
jobs_router = APIRouter(prefix="/api/jobs", tags=["jobs"])
|
||||
@@ -75,6 +76,11 @@ async def patch_job_endpoint(
|
||||
if not current_user.is_staff and job.user_id != current_user.id:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
|
||||
if body.status == "CANCELLED":
|
||||
task_service = TaskService(db)
|
||||
job = await task_service.cancel_job(job)
|
||||
return JobRead.model_validate(job)
|
||||
|
||||
job = await service.update_job(job, body)
|
||||
return JobRead.model_validate(job)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user