src/main/java/com/forum/controller/CommentsController.java
package com.forum.controller;
import com.forum.dto.CommentsDto;
import com.forum.service.CommentsService;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/comments")
@AllArgsConstructor
public class CommentsController {
private final CommentsService commentsService;
@PostMapping
public ResponseEntity<Void> createComment(@RequestBody CommentsDto commentsDto) {
commentsService.create(commentsDto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@GetMapping("/by-post/{postId}")
public ResponseEntity<List<CommentsDto>> getAllCommentsForPost(@PathVariable Long postId) {
return ResponseEntity.status(HttpStatus.OK).body(commentsService.getAllCommentsForPost(postId));
}
@GetMapping("/by-user/{userName}")
public ResponseEntity<List<CommentsDto>> getAllCommentsForUser(@PathVariable String userName) {
return ResponseEntity.status(HttpStatus.OK).body(commentsService.getAllCommentsForUser(userName));
}
}