This commit is contained in:
el 2025-06-24 18:17:53 +02:00
commit d7666f7b2c
44 changed files with 2246 additions and 0 deletions

View file

@ -0,0 +1,30 @@
# backend/repositories/document_repository.py
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from models.document import Document
from typing import Optional, List
class DocumentRepository:
def __init__(self, db: AsyncSession):
self.db = db
async def get_document_by_id(self, document_id: int, owner_id: int) -> Optional[Document]:
"""
Récupère un document par son ID et l'ID de son propriétaire.
Cela garantit qu'un utilisateur ne peut accéder qu'à ses propres documents.
"""
result = await self.db.execute(
select(Document).where(Document.id == document_id, Document.owner_id == owner_id)
)
return result.scalars().first()
async def get_all_documents_by_owner_id(self, owner_id: int) -> List[Document]:
"""
Récupère tous les documents pour un propriétaire donné.
"""
result = await self.db.execute(
select(Document).where(Document.owner_id == owner_id)
)
return result.scalars().all()
# Vous pourriez ajouter ici d'autres méthodes comme create_document, delete_document, etc.