From 1d85a40521d292764122293db90fa5bcdd890d5a Mon Sep 17 00:00:00 2001 From: alwil17 Date: Thu, 5 Jun 2025 11:31:01 +0000 Subject: [PATCH 1/2] feat: add remove_comment method to RatingService for comment management --- app/application/services/rating_service.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 From 14a500a2db93478aa3201a09578f98427a885a0c Mon Sep 17 00:00:00 2001 From: alwil17 Date: Thu, 5 Jun 2025 11:31:08 +0000 Subject: [PATCH 2/2] feat: add remove_rating_comment endpoint for comment deletion --- app/api/endpoints/rating_endpoints.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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)):