Skip to content

Commit

Permalink
[refactor] 댓글,대댓글 삭제 시 isDeleted 필드 사용하여 삭제 판단 여부 결정 테스트 오나료
Browse files Browse the repository at this point in the history
  • Loading branch information
chahyunsoo committed Aug 26, 2024
1 parent 8b8c9c9 commit b8a75b8
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public PostComment toDomain(Long userId, Long postId, String commentType) {
commentType,
null,
null,
null,
false,
null
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ussum.homepage.application.comment.service.dto.request;

import ussum.homepage.domain.comment.PostComment;
import ussum.homepage.infra.utils.DateUtils;

import java.time.LocalDateTime;

Expand All @@ -14,10 +15,11 @@ public PostComment toDomain(PostComment postComment, Long commentId, Long postId
postId,
userId,
postComment.getCommentType(),
postComment.getCreatedAt(),
String.valueOf(LocalDateTime.now()),
DateUtils.parseHourMinSecFromCustomString(postComment.getCreatedAt()),
LocalDateTime.now(),
DateUtils.parseHourMinSecFromCustomString(postComment.getLastEditedAt()),
postComment.getIsDeleted(),
postComment.getDeletedAt()
DateUtils.parseHourMinSecFromCustomString(postComment.getDeletedAt())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public PostReplyComment toDomain(Long userId,Long commentId) {
userId,
null,
null,
null,
false,
null
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ussum.homepage.application.comment.service.dto.request;

import ussum.homepage.domain.comment.PostReplyComment;
import ussum.homepage.infra.utils.DateUtils;

import java.time.LocalDateTime;

public record PostReplyCommentUpdateRequest(
String content
Expand All @@ -11,10 +14,11 @@ public PostReplyComment toDomain(PostReplyComment postReplyComment, Long userId,
content,
commentId,
userId,
postReplyComment.getCreatedAt(),
postReplyComment.getLastEditedAt(),
DateUtils.parseHourMinSecFromCustomString(postReplyComment.getCreatedAt()),
LocalDateTime.now(),
DateUtils.parseHourMinSecFromCustomString(postReplyComment.getLastEditedAt()),
postReplyComment.getIsDeleted(),
postReplyComment.getDeletedAt()
DateUtils.parseHourMinSecFromCustomString(postReplyComment.getDeletedAt())
);
}
}
16 changes: 12 additions & 4 deletions src/main/java/ussum/homepage/domain/comment/PostComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import ussum.homepage.infra.utils.DateUtils;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -13,6 +16,7 @@ public class PostComment {
private Long userId;
private String commentType;
private String createdAt;
private String updatedAt;
private String lastEditedAt;
private Boolean isDeleted;
private String deletedAt;
Expand All @@ -22,10 +26,14 @@ public static PostComment of(Long id,
Long postId,
Long userId,
String commentType,
String createdAt,
String lastEditedAt,
LocalDateTime createdAt,
LocalDateTime updatedAt,
LocalDateTime lastEditedAt,
Boolean isDeleted,
String deletedAt) {
return new PostComment(id, content, postId, userId, commentType, createdAt, lastEditedAt, isDeleted, deletedAt);
LocalDateTime deletedAt) {
return new PostComment(id, content, postId, userId, commentType, DateUtils.formatHourMinSecToCustomString(createdAt),
DateUtils.formatHourMinSecToCustomString(updatedAt), DateUtils.formatHourMinSecToCustomString(lastEditedAt),
isDeleted, DateUtils.formatHourMinSecToCustomString(deletedAt));
}

}
17 changes: 12 additions & 5 deletions src/main/java/ussum/homepage/domain/comment/PostReplyComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import lombok.Builder;
import lombok.Getter;
import ussum.homepage.infra.utils.DateUtils;

import java.time.LocalDateTime;

@Getter
@Builder
Expand All @@ -11,21 +14,25 @@ public class PostReplyComment {
private Long commentId;
private Long userId;
private String createdAt;
private String updatedAt;
private String lastEditedAt;
private Boolean isDeleted;
private String deletedAt;

public static PostReplyComment of(Long id, String content, Long commentId, Long userId, String createdAt, String lastEditedAt,
Boolean isDeleted, String deletedAt) {
public static PostReplyComment of(Long id, String content, Long commentId, Long userId,
LocalDateTime createdAt, LocalDateTime updatedAt,
LocalDateTime lastEditedAt,
Boolean isDeleted, LocalDateTime deletedAt) {
return PostReplyComment.builder()
.id(id)
.content(content)
.commentId(commentId)
.userId(userId)
.createdAt(createdAt)
.lastEditedAt(lastEditedAt)
.createdAt(DateUtils.formatHourMinSecToCustomString(createdAt))
.updatedAt(DateUtils.formatHourMinSecToCustomString(updatedAt))
.lastEditedAt(DateUtils.formatHourMinSecToCustomString(lastEditedAt))
.isDeleted(isDeleted)
.deletedAt(deletedAt)
.deletedAt(DateUtils.formatHourMinSecToCustomString(deletedAt))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public PostComment toDomain(PostCommentEntity postCommentEntity) {
postCommentEntity.getPostEntity().getId(),
postCommentEntity.getUserEntity().getId(),
String.valueOf(postCommentEntity.getCommentType()),
String.valueOf(postCommentEntity.getCreatedAt()),
String.valueOf(postCommentEntity.getLastEditedAt()),
postCommentEntity.getCreatedAt(),
postCommentEntity.getUpdatedAt(),
postCommentEntity.getLastEditedAt(),
postCommentEntity.getIsDeleted(),
String.valueOf(postCommentEntity.getDeletedAt())
postCommentEntity.getDeletedAt()
);
}

public PostCommentEntity toEntity(PostComment postComment){
LocalDateTime lastEditedAt = DateUtils.parseHourMinSecFromCustomString(postComment.getLastEditedAt());
LocalDateTime deletedEditedAt = DateUtils.parseHourMinSecFromCustomString(postComment.getDeletedAt());


return PostCommentEntity.of(
postComment.getId(),
postComment.getContent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ public PostReplyComment toDomain(PostReplyCommentEntity postReplyCommentEntity)
postReplyCommentEntity.getContent(),
postReplyCommentEntity.getPostCommentEntity().getId(),
postReplyCommentEntity.getUserEntity().getId(),
String.valueOf(postReplyCommentEntity.getCreatedAt()),
String.valueOf(postReplyCommentEntity.getLastEditedAt()),
postReplyCommentEntity.getCreatedAt(),
postReplyCommentEntity.getUpdatedAt(),
postReplyCommentEntity.getLastEditedAt(),
postReplyCommentEntity.getIsDeleted(),
String.valueOf(postReplyCommentEntity.getDeletedAt())
postReplyCommentEntity.getDeletedAt()
);
}

public PostReplyCommentEntity toEntity(PostReplyComment postReplyComment) {
LocalDateTime lastEditedAt = DateUtils.parseHourMinSecFromCustomString(postReplyComment.getLastEditedAt());
LocalDateTime deletedEditedAt = DateUtils.parseHourMinSecFromCustomString(postReplyComment.getDeletedAt());
System.out.println("postReplyComment.getUserId() = " + postReplyComment.getUserId());

return PostReplyCommentEntity.of(
postReplyComment.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import ussum.homepage.domain.comment.PostReplyComment;
import ussum.homepage.domain.comment.PostReplyCommentRepository;
import ussum.homepage.domain.reaction.service.PostReplyCommentReactionReader;
import ussum.homepage.infra.jpa.comment.entity.PostCommentEntity;
import ussum.homepage.infra.jpa.comment.entity.PostReplyCommentEntity;
import ussum.homepage.infra.jpa.comment.repository.PostReplyCommentJpaRepository;

import java.util.List;
import java.util.Optional;

import static ussum.homepage.infra.jpa.comment.entity.PostReplyCommentEntity.updateDeletedAt;
import static ussum.homepage.infra.jpa.comment.entity.PostReplyCommentEntity.updateLastEditedAt;

@Repository
Expand Down Expand Up @@ -38,14 +40,14 @@ public PostReplyComment save(PostReplyComment postReplyComment) {
}

@Override
public void delete(PostReplyComment postReplyComment) {
postReplyCommentJpaRepository.delete(postReplyCommentMapper.toEntity(postReplyComment));
public PostReplyComment update(PostReplyComment postReplyComment) {
return postReplyCommentMapper.toDomain(postReplyCommentJpaRepository.save(postReplyCommentMapper.toEntity(postReplyComment)));
}

@Override
public PostReplyComment update(PostReplyComment postReplyComment) {
// PostReplyCommentEntity postReplyCommentEntity = postReplyCommentMapper.toEntity(postReplyComment);
// updateLastEditedAt(postReplyCommentEntity);
return postReplyCommentMapper.toDomain(postReplyCommentJpaRepository.save(postReplyCommentMapper.toEntity(postReplyComment)));
public void delete(PostReplyComment postReplyComment) {
PostReplyCommentEntity postReplyCommentEntity = postReplyCommentMapper.toEntity(postReplyComment);
updateDeletedAt(postReplyCommentEntity);
postReplyCommentJpaRepository.save(postReplyCommentEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public static PostCommentEntity from(Long id) {

public static void updateDeletedAt(PostCommentEntity postComment) {
postComment.deletedAt = LocalDateTime.now();
postComment.isDeleted = false;
postComment.isDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void updateLastEditedAt(PostReplyCommentEntity postReplyComment) {

public static void updateDeletedAt(PostReplyCommentEntity postReplyComment) {
postReplyComment.deletedAt = LocalDateTime.now();
postReplyComment.isDeleted = true;
}

}

0 comments on commit b8a75b8

Please sign in to comment.