다수의 사용자가 동시에 방에 입장했을때, 동시성 제어를 통해 방의 인원 제한에 따른 인원 수 관리
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api")
public class CommentController {
private final CommentService commentService;
private final CommentReportService commentReportService;
//댓글 등록 메서드
@PostMapping("/comments")
public ResponseForm<CommentForm> createComment(@RequestBody CommentForm commentForm) {
try {
// CommentService를 사용하여 새로운 댓글을 생성. commentForm 객체를 전달하여 createComment 메서드를 호출.
Comment comment = commentService.createComment(commentForm);
// 생성된 Comment 객체를 CommentForm 객체로 변환. 이 변환 작업은 보안 또는 데이터 전송을 위한 용도.
CommentForm createCommentForm = convertToCommentForm(comment);
// 변환된 CommentForm 객체를 ResponseForm에 담아 클라이언트에게 HTTP 상태 코드와 함께 응답.
return new ResponseForm<>(HttpStatus.OK, createCommentForm, "댓글 등록을 성공적으로 완료했습니다!");
} catch (Exception e) {
// 예기치 않은 오류가 발생할 경우 로그를 기록, INTERNAL_SERVER_ERROR 상태 코드와 함께 오류 메시지를 반환.
log.error("Unexpected error", e);
return new ResponseForm<>(HttpStatus.INTERNAL_SERVER_ERROR, null, "Unexpected error occurred.");
}
}
@Builder빌더는 객체 생성