36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import TYPE_CHECKING, Protocol
|
||
|
|
from uuid import UUID
|
||
|
|
|
||
|
|
from sqlalchemy import select
|
||
|
|
|
||
|
|
from core.db.base_repository import BaseRepository
|
||
|
|
from models.automation_jobs import AutomationJob
|
||
|
|
|
||
|
|
if TYPE_CHECKING:
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
|
||
|
|
class MemoryRepositoryLike(Protocol):
|
||
|
|
async def get_job_by_id_and_owner(
|
||
|
|
self, *, job_id: UUID, owner_id: UUID
|
||
|
|
) -> AutomationJob | None: ...
|
||
|
|
|
||
|
|
|
||
|
|
class MemoryRepository(BaseRepository[AutomationJob]):
|
||
|
|
def __init__(self, session: AsyncSession) -> None:
|
||
|
|
super().__init__(session=session, model=AutomationJob)
|
||
|
|
|
||
|
|
async def get_job_by_id_and_owner(
|
||
|
|
self, *, job_id: UUID, owner_id: UUID
|
||
|
|
) -> AutomationJob | None:
|
||
|
|
stmt = (
|
||
|
|
select(AutomationJob)
|
||
|
|
.where(AutomationJob.id == job_id)
|
||
|
|
.where(AutomationJob.owner_id == owner_id)
|
||
|
|
.where(AutomationJob.deleted_at.is_(None))
|
||
|
|
)
|
||
|
|
result = await self._session.execute(stmt)
|
||
|
|
return result.scalar_one_or_none()
|