Skip to content

Commit

Permalink
Merge branch 'dev' into feat/diary
Browse files Browse the repository at this point in the history
  • Loading branch information
chjcode authored Aug 10, 2024
2 parents fc6aeba + dbc586f commit cf6ab35
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- dev

jobs:
deploy:
code_review:
runs-on: ubuntu-latest

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record CommentResponseDTO(
boolean deleted,
String createdDate,
String createdAt,
int depth,
List<CommentResponseDTO> childComments
) {
public static CommentResponseDTO from(Comment comment) {
Expand All @@ -24,6 +25,7 @@ public static CommentResponseDTO from(Comment comment) {
comment.isDeleted(),
comment.getCreatedAt().format(DateTimeFormatter.ofPattern("yy년 MM월 dd일")),
comment.getCreatedAt().format(DateTimeFormatter.ofPattern("HH:mm")),
comment.getDepth(),
comment.getChildComments().stream().map(CommentResponseDTO::from).collect(Collectors.toList())
);
}
Expand All @@ -36,6 +38,7 @@ public static CommentResponseDTO fromDeleted(Comment comment) {
true,
null,
null,
comment.getDepth(),
comment.getChildComments().stream().map(CommentResponseDTO::from).collect(Collectors.toList())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ public record CommentSaveRequestDTO(
String content,
Long parentCommentId
) {
public Comment toEntity(Member member, Diary diary, Comment parentComment) {
public Comment toEntity(Member member, Diary diary, Comment parentComment, int depth) {
return Comment.builder()
.member(member)
.diary(diary)
.content(content)
.parentComment(parentComment)
.depth(depth)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ public class Comment extends BaseTimeEntity {

private boolean deleted;

@Column(nullable = false)
private int depth;

@Builder
protected Comment(Member member, Diary diary, String content, Comment parentComment) {
protected Comment(Member member, Diary diary, String content, Comment parentComment, int depth) {
this.member = member;
this.diary = diary;
this.content = content;
this.parentComment = parentComment;
this.deleted = false;
this.depth = depth;
}

public void update(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public CommentResponseDTO save(Long diaryId, CommentSaveRequestDTO requestDTO, L
Member member = getMemberById(logInMemberId);
Diary diary = getDiaryById(diaryId);
Comment parentComment = getParentCommentById(requestDTO.parentCommentId());
Comment comment = requestDTO.toEntity(member, diary, parentComment);

int commentDepth = calculateCommentDepth(parentComment);
validateCommentDepth(commentDepth);
Comment comment = requestDTO.toEntity(member, diary, parentComment, commentDepth);
commentDAO.save(comment);

return CommentResponseDTO.from(comment);
Expand Down Expand Up @@ -125,6 +128,13 @@ private Comment getCommentById(Long id) {
.orElseThrow(() -> new SystemException(ClientErrorCode.COMMENT_NOT_FOUND_ERR));
}

private int calculateCommentDepth(Comment parentComment) {
if (parentComment == null) {
return 0;
}
return parentComment.getDepth() + 1;
}

private void validateCommentAuthor(Member member, Comment comment) {
if (!member.equals(comment.getMember())) {
throw new SystemException(ClientErrorCode.AUTHOR_MISMATCH_ERR);
Expand All @@ -136,4 +146,10 @@ private void validateNotDeleted(Comment comment) {
throw new SystemException(ClientErrorCode.COMMENT_ALREADY_DELETED_ERR);
}
}

private void validateCommentDepth(int depth) {
if (depth > 1) {
throw new SystemException(ClientErrorCode.COMMENT_DEPTH_EXCEEDED_ERR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public DiarySaveResponseDTO update(Long id, DiaryUpdateRequestDTO requestDto) {
}

/**
* diaryId를 이용해서 diaryTag, MemberTag 를 찾아내기
* diaryTag 삭제 -> deleteAllInBatch 고려해보기
* MemberTag 삭제
* 해당 일기의 좋아요 찾기 및 삭제
* diaryId를 이용해서 diaryTag, MemberTag 를 찾아내기 diaryTag 삭제 -> deleteAllInBatch 고려해보기 MemberTag 삭제 해당 일기의 좋아요 찾기 및 삭제
* 이미지 삭제
*/
@Transactional
Expand Down Expand Up @@ -275,6 +272,7 @@ private void decrementTagsCount(List<TagList> tags) {
}
}
}

private void removeDiaryLikes(Long diaryId) {
List<DiaryLike> diaryLikes = diaryLikeDAO.findAllByDiaryId(diaryId);
diaryLikeDAO.deleteAll(diaryLikes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
Expand Down Expand Up @@ -40,14 +38,6 @@ public ResponseEntity<?> uploadDiaryImage(
.body(imageService.uploadImage(image, FileFolder.PERSONAL_DIARY));
}

@DeleteMapping("/diary/{diaryId}")
public ResponseEntity<?> deleteDiaryImage(
@PathVariable Long diaryId
) {
imageService.deleteImage(diaryId);
return ResponseEntity.ok().build();
}

private ResponseEntity<?> sendImage(String mainBannerUrl) throws IOException {
Resource resource = new ClassPathResource(mainBannerUrl);
if (!resource.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void mappingImageToDiary(Diary diary, Long imageId) {

public void deleteImageAndMapping(Diary diary) {
diaryToImageDAO.findByDiaryId(diary.getId()).ifPresent(diaryImage -> {
imageService.deleteImage(diaryImage.getId());
imageService.deleteImage(diaryImage.getImage().getId());
diaryToImageDAO.delete(diaryImage);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ClientErrorCode implements ErrorCodeModel {
IMAGE_MAPPING_NOT_FOUND_ERR(400, "IMAGE_MAPPING_NOT_FOUND_ERR", "해당 이미지를 찾을 수 없습니다.(이미지 등록 값 없음)"),
AUTHOR_MISMATCH_ERR(403, "AUTHOR_MISMATCH_ERR", "작성자가 아닙니다."),
COMMENT_ALREADY_DELETED_ERR(400, "COMMENT_ALREADY_DELETED_ERR", "이미 삭제된 댓글입니다."),
COMMENT_DEPTH_EXCEEDED_ERR(400, "COMMENT_DEPTH_EXCEEDED_ERR", "댓글은 대댓글까지만 허용합니다."),

VALIDATION_ERR(400, "VALIDATION_ERR", "잘못된 입력입니다. 올바른 값을 입력해주세요."),
PERMISSION_ERR(403, "PERMISSION_ERR", "접근 권한이 없습니다. 관리자에게 문의하세요."),
Expand Down

0 comments on commit cf6ab35

Please sign in to comment.