Skip to content

Commit 038a5f2

Browse files
authored
Merge pull request #482 from TaskFlow-CLAP/CLAP-375
CLAP-375 comment 테이블 반정규화
2 parents 02a3a34 + 87ec0d9 commit 038a5f2

File tree

19 files changed

+84
-107
lines changed

19 files changed

+84
-107
lines changed

src/main/java/clap/server/adapter/inbound/web/dto/history/response/FindTaskHistoryResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static record CommentFileDetails(
3939
Long commentId,
4040
String nickName,
4141
String profileImageUrl,
42-
boolean isModified,
4342
String fileName,
4443
String url,
4544
String size

src/main/java/clap/server/adapter/outbound/persistense/AttachmentPersistenceAdapter.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,18 @@ public void saveAll(final List<Attachment> attachments) {
3737
}
3838

3939
@Override
40-
public List<Attachment> findAllByTaskIdAndCommentIsNull(final Long taskId) {
41-
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNull(taskId);
40+
public List<Attachment> findAllByTaskId(final Long taskId) {
41+
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskId(taskId);
4242
return attachmentEntities.stream()
4343
.map(attachmentPersistenceMapper::toDomain)
4444
.collect(Collectors.toList());
4545
}
4646

4747
@Override
48-
public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
49-
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(taskId, attachmentIds);
48+
public List<Attachment> findAllByTaskIdAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
49+
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndAttachmentIdIn(taskId, attachmentIds);
5050
return attachmentEntities.stream()
5151
.map(attachmentPersistenceMapper::toDomain)
5252
.collect(Collectors.toList());
5353
}
54-
55-
@Override
56-
public Optional<Attachment> findByCommentId(final Long commentId) {
57-
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentId(commentId);
58-
return attachmentEntity.map(attachmentPersistenceMapper::toDomain);
59-
}
60-
61-
@Override
62-
public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
63-
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNull(taskId);
64-
return attachmentEntities.stream()
65-
.map(attachmentPersistenceMapper::toDomain)
66-
.collect(Collectors.toList());
67-
}
68-
69-
@Override
70-
public boolean exitsByCommentId(final Long commentId) {
71-
return attachmentRepository.existsByComment_CommentId(commentId);
72-
}
7354
}

src/main/java/clap/server/adapter/outbound/persistense/CommentPersistenceAdapter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ public Comment saveComment(final Comment comment) {
3434
public void deleteCommentWithTaskHistory(final Long commentId) {
3535
commentRepository.deleteCommentWithTaskHistory(commentId);
3636
}
37-
38-
@Override
39-
public void deleteComment(final Comment comment) {
40-
commentRepository.delete(commentPersistenceMapper.toEntity(comment));
41-
}
4237
}

src/main/java/clap/server/adapter/outbound/persistense/entity/member/MemberEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public class MemberEntity extends BaseTimeEntity {
5454

5555
@Column(name = "kakaowork_notification_enabled")
5656
@Builder.Default
57-
private Boolean kakaoworkNotificationEnabled = Boolean.TRUE;;
57+
private Boolean kakaoworkNotificationEnabled = Boolean.TRUE;
5858

5959
@Column(name = "email_notification_enabled")
6060
@Builder.Default
61-
private Boolean emailNotificationEnabled = Boolean.TRUE;;
61+
private Boolean emailNotificationEnabled = Boolean.TRUE;
6262

6363
@ManyToOne(fetch = FetchType.LAZY)
6464
@JoinColumn(name = "admin_id")

src/main/java/clap/server/adapter/outbound/persistense/entity/task/AttachmentEntity.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public class AttachmentEntity extends BaseTimeEntity {
3535
@JoinColumn(name = "task_id")
3636
private TaskEntity task;
3737

38-
@OneToOne(fetch = FetchType.LAZY)
39-
@JoinColumn(name = "comment_id")
40-
private CommentEntity comment;
41-
4238
@Column(name= "is_deleted", nullable = false)
4339
@Builder.Default
4440
private boolean isDeleted = Boolean.FALSE;

src/main/java/clap/server/adapter/outbound/persistense/entity/task/CommentEntity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,18 @@ public class CommentEntity extends BaseTimeEntity {
3535
@Column(name = "content")
3636
private String content;
3737

38+
@Column
39+
private String originalName;
40+
41+
@Column
42+
private String fileUrl;
43+
44+
@Column
45+
private String fileSize;
46+
3847
@Column(name = "is_modified", nullable = false)
39-
private boolean isModified;
48+
@Builder.Default
49+
private boolean isModified = Boolean.FALSE;
4050

4151
@Column(name="is_deleted", nullable = false)
4252
@Builder.Default

src/main/java/clap/server/adapter/outbound/persistense/repository/task/AttachmentRepository.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
@Repository
1010
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
11-
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNull(Long taskId);
12-
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
13-
Optional<AttachmentEntity> findByComment_CommentId(Long commentId);
14-
boolean existsByComment_CommentId(Long commentId);
15-
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNull(Long taskId);
11+
List<AttachmentEntity> findAllByTask_TaskId(Long taskId);
12+
List<AttachmentEntity> findAllByTask_TaskIdAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
1613
}

src/main/java/clap/server/application/mapper/response/TaskHistoryResponseMapper.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private TaskHistoryResponseMapper() {
1414
throw new IllegalArgumentException("Utility class");
1515
}
1616

17-
public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory> taskHistories, List<Attachment> attachments) {
17+
public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory> taskHistories) {
1818
List<FindTaskHistoryResponse.TaskHistoryResponse> historyResponses = taskHistories.stream()
1919
.map(taskHistory -> {
2020
FindTaskHistoryResponse.Details details =
@@ -47,25 +47,20 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
4747
case COMMENT_FILE -> new FindTaskHistoryResponse.Details(
4848
null,
4949
null,
50-
attachments.stream()
51-
.filter(attachment -> attachment.getComment().getCommentId().equals(taskHistory.getComment().getCommentId()))
52-
.findFirst()
53-
.map(attachment -> new FindTaskHistoryResponse.CommentFileDetails(
54-
taskHistory.getComment().getCommentId(),
55-
taskHistory.getComment().getMember().getNickname(),
56-
taskHistory.getComment().getMember().getImageUrl(),
57-
taskHistory.getComment().isModified(),
58-
attachment.getOriginalName(),
59-
attachment.getFileUrl(),
60-
attachment.getFileSize()
61-
))
62-
.orElse(null)
50+
new FindTaskHistoryResponse.CommentFileDetails(
51+
taskHistory.getComment().getCommentId(),
52+
taskHistory.getComment().getMember().getNickname(),
53+
taskHistory.getComment().getMember().getImageUrl(),
54+
taskHistory.getComment().getOriginalName(),
55+
taskHistory.getComment().getFileUrl(),
56+
taskHistory.getComment().getFileSize()
57+
)
6358
);
6459
};
6560
return new FindTaskHistoryResponse.TaskHistoryResponse(
6661
taskHistory.getTaskHistoryId(),
67-
taskHistory.getUpdatedAt().toLocalDate(),
68-
taskHistory.getUpdatedAt().toLocalTime(),
62+
taskHistory.getCreatedAt().toLocalDate(),
63+
taskHistory.getCreatedAt().toLocalTime(),
6964
taskHistory.getType(),
7065
details
7166
);

src/main/java/clap/server/application/port/outbound/task/CommandCommentPort.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ public interface CommandCommentPort {
77
Comment saveComment(Comment comment);
88

99
void deleteCommentWithTaskHistory(Long commentId);
10-
11-
void deleteComment(Comment comment);
1210
}

src/main/java/clap/server/application/port/outbound/task/LoadAttachmentPort.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
import clap.server.domain.model.task.Attachment;
44

55
import java.util.List;
6-
import java.util.Optional;
76

87

98
public interface LoadAttachmentPort {
10-
List<Attachment> findAllByTaskIdAndCommentIsNull(Long taskId);
11-
List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(Long taskId, List<Long> attachmentIds);
12-
Optional<Attachment> findByCommentId(Long commentId);
13-
List<Attachment> findAllByTaskIdAndCommentIsNotNull(Long taskId);
14-
boolean exitsByCommentId(Long commentId);
9+
List<Attachment> findAllByTaskId(Long taskId);
10+
List<Attachment> findAllByTaskIdAndAttachmentId(Long taskId, List<Long> attachmentIds);
1511
}

0 commit comments

Comments
 (0)