CommentApiController는 사용자의 댓글과 관련된 요청을 처리하는 컨트롤러입니다. 이 컨트롤러는 댓글을 생성, 읽기, 업데이트, 삭제하는 기능을 제공합니다. 사용자의 요청에 따라 적절한 서비스를 호출하여 댓글 데이터를 처리하고, 처리 결과를 사용자에게 응답으로 반환합니다.

package tomato.classifier.api;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tomato.classifier.dto.CommentDto;
import tomato.classifier.service.CommentService;

import javax.transaction.Transactional;

@RestController
@RequiredArgsConstructor
public class CommentApiController {

    private final CommentService commentService;

    @Transactional
    @PostMapping("/article/{articleId}/comment-add")
    public ResponseEntity<CommentDto> write(@PathVariable Integer articleId, @RequestBody CommentDto commentDto) {

        CommentDto dto = commentService.write(articleId, commentDto);

        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @Transactional
    @PatchMapping("/comment-edit/{commentId}")
    public ResponseEntity<CommentDto> edit(@PathVariable Integer commentId, @RequestBody CommentDto commentDto) {

        CommentDto edit = commentService.edit(commentId, commentDto);

        return ResponseEntity.status(HttpStatus.OK).body(edit);
    }

    @Transactional
    @DeleteMapping("/comment-delete/{commentId}")
    public ResponseEntity<CommentDto> delete(@PathVariable Integer commentId, @RequestBody CommentDto commentDto) {

        CommentDto deleted = commentService.delete(commentId, commentDto);

        return ResponseEntity.status(HttpStatus.OK).body(deleted);
        // delete_yn 여부에 따라 프론트에 보여지는 건 아직 구현 안함
    }
}