diff --git a/app/api/endpoints/rating_endpoints.py b/app/api/endpoints/rating_endpoints.py index a8fa565..274086b 100644 --- a/app/api/endpoints/rating_endpoints.py +++ b/app/api/endpoints/rating_endpoints.py @@ -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)): diff --git a/app/application/services/rating_service.py b/app/application/services/rating_service.py index 2c9561b..d4fc766 100644 --- a/app/application/services/rating_service.py +++ b/app/application/services/rating_service.py @@ -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