backend
This commit is contained in:
commit
d7666f7b2c
44 changed files with 2246 additions and 0 deletions
0
backend/crud/__init__py
Normal file
0
backend/crud/__init__py
Normal file
29
backend/crud/ai_interaction.py
Normal file
29
backend/crud/ai_interaction.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from sqlalchemy.orm import Session
|
||||
from models import ai_interaction as models_ai_interaction
|
||||
from schemas import ai_interaction as schemas_ai_interaction
|
||||
|
||||
def create_ai_interaction(db: Session, ai_interaction: schemas_ai_interaction.AiInteractionCreate):
|
||||
"""Crée une nouvelle interaction IA dans la base de données."""
|
||||
db_ai_interaction = models_ai_interaction.AiInteraction(
|
||||
user_id=ai_interaction.user_id,
|
||||
document_id=ai_interaction.document_id,
|
||||
job_offer_text=ai_interaction.job_offer_text,
|
||||
cv_text_used=ai_interaction.cv_text_used,
|
||||
ai_request=ai_interaction.ai_request,
|
||||
ai_response=ai_interaction.ai_response,
|
||||
score=ai_interaction.score,
|
||||
analysis_results=ai_interaction.analysis_results,
|
||||
interaction_type=ai_interaction.interaction_type
|
||||
)
|
||||
db.add(db_ai_interaction)
|
||||
db.commit()
|
||||
db.refresh(db_ai_interaction)
|
||||
return db_ai_interaction
|
||||
|
||||
def get_ai_interactions_by_user(db: Session, user_id: int):
|
||||
"""Récupère toutes les interactions IA d'un utilisateur."""
|
||||
return db.query(models_ai_interaction.AiInteraction).filter(models_ai_interaction.AiInteraction.user_id == user_id).all()
|
||||
|
||||
def get_ai_interaction_by_id(db: Session, interaction_id: int):
|
||||
"""Récupère une interaction IA par son ID."""
|
||||
return db.query(models_ai_interaction.AiInteraction).filter(models_ai_interaction.AiInteraction.id == interaction_id).first()
|
38
backend/crud/document.py
Normal file
38
backend/crud/document.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# backend/crud/document.py
|
||||
from sqlalchemy.orm import Session
|
||||
# Importations ABSOLUES
|
||||
from models import document as models_document
|
||||
from schemas import document as schemas_document
|
||||
from typing import Optional
|
||||
|
||||
def create_document(db: Session, document: schemas_document.DocumentCreate, filepath: str, owner_id: int):
|
||||
db_document = models_document.Document(
|
||||
filename=document.filename,
|
||||
filepath=filepath,
|
||||
owner_id=owner_id
|
||||
)
|
||||
db.add(db_document)
|
||||
db.commit()
|
||||
db.refresh(db_document)
|
||||
return db_document
|
||||
|
||||
def get_documents_by_owner(db: Session, owner_id: int):
|
||||
return db.query(models_document.Document).filter(models_document.Document.owner_id == owner_id).all()
|
||||
|
||||
# Ceci est la définition correcte et finale de get_document_by_id
|
||||
def get_document_by_id(db: Session, document_id: int, owner_id: int) -> Optional[models_document.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.
|
||||
"""
|
||||
return db.query(models_document.Document).filter(
|
||||
models_document.Document.id == document_id,
|
||||
models_document.Document.owner_id == owner_id
|
||||
).first()
|
||||
|
||||
def delete_document(db: Session, document_id: int):
|
||||
db_document = db.query(models_document.Document).filter(models_document.Document.id == document_id).first()
|
||||
if db_document:
|
||||
db.delete(db_document)
|
||||
db.commit()
|
||||
return db_document
|
20
backend/crud/user.py
Normal file
20
backend/crud/user.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from sqlalchemy.orm import Session
|
||||
# Importations ABSOLUES
|
||||
from models import user as models_user
|
||||
from schemas import user as schemas_user
|
||||
from core.hashing import get_password_hash # <-- NOUVEAU
|
||||
|
||||
def get_user_by_email(db: Session, email: str):
|
||||
return db.query(models_user.User).filter(models_user.User.email == email).first()
|
||||
|
||||
def create_user(db: Session, user: schemas_user.UserCreate):
|
||||
hashed_password = get_password_hash(user.password)
|
||||
db_user = models_user.User(
|
||||
email=user.email,
|
||||
hashed_password=hashed_password,
|
||||
name=user.name
|
||||
)
|
||||
db.add(db_user)
|
||||
db.commit()
|
||||
db.refresh(db_user)
|
||||
return db_user
|
Loading…
Add table
Add a link
Reference in a new issue