mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 04:02:49 +05:30
Added job repository, implemented create and listall functions
This commit is contained in:
25
app/repositories/job_repository.py
Normal file
25
app/repositories/job_repository.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from typing import List, Optional, Any, Dict
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.db.models.job import Job
|
||||
|
||||
|
||||
class JobRepository:
|
||||
def __init__(self, db: AsyncSession):
|
||||
self.db = db
|
||||
|
||||
async def create(self, filename: str) -> Job:
|
||||
job = Job(filename=filename, status="pending")
|
||||
self.db.add(job)
|
||||
await self.db.flush()
|
||||
return job
|
||||
|
||||
|
||||
async def list_all(self, status: Optional[str] = None) -> List[Job]:
|
||||
query = select(Job)
|
||||
if status:
|
||||
query = query.where(Job.status == status)
|
||||
query = query.order_by(Job.created_at.desc())
|
||||
result = await self.db.execute(query)
|
||||
return list(result.scalars().all())
|
||||
|
||||
Reference in New Issue
Block a user