Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/api/endpoints/rating_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def update_rating(rating_id: int, rating_dto: RatingUpdateDTO, db: Session = Dep
raise HTTPException(status_code=404, detail="Rating not found")
return rating

# Endpoint pour supprimer le commentaire d'un rating
@router.delete("/{rating_id}/comment", status_code=200, response_model=RatingResponse)
def remove_rating_comment(rating_id: int, db: Session = Depends(get_db), role: str = Depends(require_role(["admin"]))):
rating_service = RatingService(db)
rating = rating_service.remove_comment(rating_id)
if not rating:
raise HTTPException(status_code=404, detail="Rating not found")
return rating

# Endpoint pour supprimer un rating
@router.delete("/{rating_id}", status_code=204)
def delete_rating(rating_id: int, db: Session = Depends(get_db), token: str = Depends(oauth2_scheme), current_user: UserResponse = Depends(get_current_user)):
Expand Down
20 changes: 20 additions & 0 deletions app/application/services/rating_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ def update_rating(self, rating_id: int, rating_data: RatingUpdateDTO) -> Optiona

def delete_rating(self, rating_id: int) -> bool:
return self.repository.delete(rating_id)

def remove_comment(self, rating_id: int):
"""
Remove the comment from a rating without affecting the score

Args:
rating_id: ID of the rating to modify

Returns:
The updated rating or None if not found
"""
rating = self.repository.get_by_id(rating_id)
if not rating:
return None

# Remove the comment but keep the score
rating.comment = None
self.repository.update(rating)

return rating