Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/com/example/prdoit/controller/CommentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.prdoit.controller;

import com.example.prdoit.dto.comment.*;
import com.example.prdoit.service.comment.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comments")
public class CommentController {

private final CommentService commentService;

// 1. 댓글 조회
@GetMapping("/{contentId}")
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable String contentId) {
return ResponseEntity.ok(commentService.getCommentList(contentId));
}

// 2. 댓글 작성
@PostMapping
public ResponseEntity<String> createComment(@RequestBody CommentRequestDto commentRequestDto) {
commentService.postComment(commentRequestDto);
return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!");
}

// 3. 대댓글 작성
@PostMapping("/reply")
public ResponseEntity<String> createReply(@RequestBody CommentReplyRequestDto commentReplyRequestDto) {
commentService.postCommentReply(commentReplyRequestDto);
return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!");
}

// 4. 댓글 수정
@PatchMapping
public ResponseEntity<String> updateComment(@RequestBody CommentPatchDto commentPatchDto) {
commentService.patchComment(commentPatchDto);
return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!");
}

// 5.대댓글 수정
@PatchMapping("/reply")
public ResponseEntity<String> updateReply(@RequestBody CommentReplyPatchDto commentReplyPatchDto) {
commentService.patchCommentReply(commentReplyPatchDto);
return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!");
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/prdoit/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public ResponseEntity<Object> getBurndownList(@PathVariable String projectId, @P
}
}

@DeleteMapping("/{projectId}")
public ResponseEntity<Object> deleteProject(@PathVariable String projectId) {
log.info("[deleteProject] 프로젝트 삭제 요청");
try{
projectService.deleteProject(projectId);
return ResponseEntity.ok("프로젝트 삭제에 성공했습니다.");
} catch (RuntimeException e){
log.error("[deleteProject] {}", e.getMessage());
return ResponseEntity.badRequest().body("프로젝트 삭제에 실패했습니다.");
}
}

/*
@PutMapping("/product")
public ResponseEntity<Object> putBacklog(@RequestBody BacklogPutDto backlogPutDto) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/example/prdoit/dto/comment/CommentPatchDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentPatchDto {

private int commentId; // 수정할 댓글 ID
private String commentContent; // 수정된 댓글 내용
private LocalDateTime commentDate; // 수정된 날짜
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentReplyPatchDto {

private int commentReplyId; // 수정할 대댓글 ID
private String commentReplyContent; // 수정된 대댓글 내용
private LocalDateTime commentReplyDate; // 수정된 날짜
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentReplyRequestDto {

private int commentId; // 대댓글이 달릴 원본 댓글 ID
private String commentReplyContent; // 대댓글 내용
private String commentReplyNickname; // 대댓글 작성자 닉네임
private LocalDateTime commentReplyDate; // 대댓글 작성 날짜
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentReplyResponseDto {

private int commentReplyId; // 대댓글 ID
private String commentReplyContent; // 대댓글 내용
private String commentReplyNickname; // 작성자 닉네임
private LocalDateTime commentReplyDate; // 대댓글 작성 날짜
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentRequestDto {

private String contentId; // 댓글 달릴 게시글 ID
private String commentContent; // 댓글 내용
private String commentNickname; // 댓글 작성자 닉네임
private LocalDateTime commentDate; // 댓글 작성 날짜
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommentResponseDto {

private int commentId; // 댓글 ID
private String commentContent; // 댓글 내용
private String commentNickname; // 작성자 닉네임
private LocalDateTime commentDate; // 댓글 작성 날짜
private List<CommentReplyResponseDto> commentReplyResponseDtoList; // 대댓글 리스트
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ public class ProjectLevelContentTable {
@ManyToOne
@JoinColumn(name = "projectId")
private ProjectTable projectId;


@OneToMany(mappedBy = "levelContentId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<BacklogTable> backlogList;
}
4 changes: 3 additions & 1 deletion src/main/java/com/example/prdoit/model/ProjectTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public class ProjectTable {
@JoinColumn(name = "id")
private IdTable id;


@OneToMany(mappedBy = "projectId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<ProjectLevelContentTable> projectLevelContentList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.service.comment;

import com.example.prdoit.dto.comment.*;

import java.util.List;

public interface CommentService {

List<CommentResponseDto> getCommentList(String contentId);

void postComment(CommentRequestDto commentRequestDto);

void postCommentReply(CommentReplyRequestDto commentReplyRequestDto);

void patchComment(CommentPatchDto commentPatchDto);

void patchCommentReply(CommentReplyPatchDto commentReplyPatchDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.example.prdoit.service.comment;

import com.example.prdoit.dto.comment.*;
import com.example.prdoit.exception.CustomException;
import com.example.prdoit.model.CommentCommentTable;
import com.example.prdoit.model.CommentTable;
import com.example.prdoit.model.ContentTable;
import com.example.prdoit.repository.CommentCommentTableRepository;
import com.example.prdoit.repository.CommentTableRepository;
import com.example.prdoit.repository.ContentTableRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class CommentServiceImpl implements CommentService {

private final CommentTableRepository commentTableRepository;
private final CommentCommentTableRepository commentCommentTableRepository;
private final ContentTableRepository contentTableRepository;

// 1. 댓글 목록 조회 (GET)
@Override
public List<CommentResponseDto> getCommentList(String contentId) {
log.info("[getCommentList] 댓글 목록 조회 시작 - Content ID: {}", contentId);

ContentTable contentTable = contentTableRepository.findById(contentId)
.orElseThrow(() -> new CustomException("해당 게시글이 없습니다. ID = " + contentId));

return contentTable.getCommentTable().stream()
.map(comment -> CommentResponseDto.builder()
.commentId(comment.getCommentId())
.commentContent(comment.getCommentContent())
.commentNickname(comment.getCommentNickname())
.commentDate(comment.getCommentDate())
.commentReplyResponseDtoList(comment.getCommentCommentTable().stream()
.map(reply -> CommentReplyResponseDto.builder()
.commentReplyId(reply.getCommentCommentId())
.commentReplyContent(reply.getCommentCommentContent())
.commentReplyNickname(reply.getUserNickname())
.commentReplyDate(reply.getCommentCommentDate())
.build())
.collect(Collectors.toList()))
.build())
.collect(Collectors.toList());
}

// 2. 댓글 작성 (POST)
@Override
public void postComment(CommentRequestDto commentRequestDto) {
log.info("[postComment] 댓글 등록 시작 - Content ID: {}", commentRequestDto.getContentId());

ContentTable contentTable = contentTableRepository.findById(commentRequestDto.getContentId())
.orElseThrow(() -> new CustomException("해당 게시글이 없습니다."));

commentTableRepository.save(CommentTable.builder()
.commentContent(commentRequestDto.getCommentContent())
.commentNickname(commentRequestDto.getCommentNickname())
.commentDate(commentRequestDto.getCommentDate())
.contentId(contentTable)
.build());

log.info("[postComment] 댓글 등록을 완료했습니다.");
}

// 3. 대댓글 작성 (POST)
@Override
public void postCommentReply(CommentReplyRequestDto commentReplyRequestDto) {
log.info("[postCommentReply] 대댓글 등록 시작");

CommentTable parentComment = commentTableRepository.findById(commentReplyRequestDto.getCommentId())
.orElseThrow(() -> new CustomException("해당 댓글이 없습니다."));

commentCommentTableRepository.save(CommentCommentTable.builder()
.commentCommentContent(commentReplyRequestDto.getCommentReplyContent())
.userNickname(commentReplyRequestDto.getCommentReplyNickname())
.commentCommentDate(commentReplyRequestDto.getCommentReplyDate())
.commentId(parentComment)
.build());

log.info("[postCommentReply] 대댓글 등록을 완료했습니다.");
}

// 4. 댓글 수정 (PATCH)
@Override
public void patchComment(CommentPatchDto commentPatchDto) {
log.info("[patchComment] 댓글 수정 시작 - Comment ID: {}", commentPatchDto.getCommentId());

CommentTable comment = commentTableRepository.findById(commentPatchDto.getCommentId())
.orElseThrow(() -> new CustomException("해당 댓글이 없습니다."));

comment.setCommentContent(commentPatchDto.getCommentContent());
comment.setCommentDate(commentPatchDto.getCommentDate());
commentTableRepository.save(comment);

log.info("[patchComment] 댓글 수정이 완료되었습니다.");
}

// 5. 대댓글 수정 (PATCH)
@Override
public void patchCommentReply(CommentReplyPatchDto commentReplyPatchDto) {
log.info("[patchCommentReply] 대댓글 수정 시작 - CommentReply ID: {}", commentReplyPatchDto.getCommentReplyId());

CommentCommentTable reply = commentCommentTableRepository.findById(commentReplyPatchDto.getCommentReplyId())
.orElseThrow(() -> new CustomException("해당 대댓글이 없습니다."));

reply.setCommentCommentContent(commentReplyPatchDto.getCommentReplyContent());
reply.setCommentCommentDate(commentReplyPatchDto.getCommentReplyDate());
commentCommentTableRepository.save(reply);

log.info("[patchCommentReply] 대댓글 수정이 완료되었습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface ProjectService {
void deleteProjectContent(ContentDeleteDto contentDeleteDto);

BacklogAddDto getBacklog(String projectId, String backlogTaskId);

void deleteProject(String projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ public BacklogAddDto getBacklog(String projectId, String backlogTaskId) {

}

@Override
public void deleteProject(String projectId) {
log.info("[deleteProject] 프로젝트 삭제 시작");
ProjectTable projectTable = projectTableRepository.findById(projectId).orElseThrow(() -> new CustomException("존재하지 않는 프로젝트입니다."));
try {
projectTableRepository.delete(projectTable);
} catch (CustomException e) {
log.error(e.getMessage());
throw new CustomException(e.getMessage());
} catch (RuntimeException e) {
log.error(e.getMessage());
throw e;
}
}

// internal method
//ContentDto를 받아서 ProjectLevelContentTable을 생성
public ProjectLevelContentTable createContent(String projectId, int projectLevel, String projectContent) {
Expand Down