package com.krishna.controller; import com.krishna.dto.CommentDTO; import com.krishna.model.CommentModel; import com.krishna.service.CommentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; @CrossOrigin(origins = {"http://localhost:8080", "http://localhost:8081", "http://127.0.0.1:5500", "http://localhost:5173/", "https://my-media-718.netlify.app/"}) @RestController @RequestMapping("/comments") public class CommentController { @Autowired private CommentService commentService; @PostMapping("/add") public ResponseEntity addComment(@RequestBody CommentDTO dto) { try { CommentModel comment = commentService.addComment(dto); return ResponseEntity.ok(comment); } catch (Exception e) { return ResponseEntity.badRequest().body("Error: " + e.getMessage()); } } @GetMapping("/post/{postId}") public ResponseEntity> getComments(@PathVariable Long postId) { return ResponseEntity.ok(commentService.getCommentsByPost(postId)); } // ✅ Corrected delete mapping for deleting a COMMENT @DeleteMapping("/{commentId}") public ResponseEntity deleteComment(@PathVariable Long commentId) { try { commentService.deleteComment(commentId); return ResponseEntity.ok("Comment deleted successfully."); } catch (Exception e) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Error: " + e.getMessage()); } } }