Skip to content

Commit 87ec0d9

Browse files
committed
CLAP-375 Fix: 작업 관련 조회시 notnull 관련 jpa 쿼리 제거
1 parent c1bd0d5 commit 87ec0d9

File tree

9 files changed

+14
-66
lines changed

9 files changed

+14
-66
lines changed

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/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/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
}

src/main/java/clap/server/application/service/history/CommandCommentService.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public class CommandCommentService implements EditCommentUsecase, DeleteCommentU
3232

3333
private final MemberService memberService;
3434
private final CommentService commentService;
35-
3635
private final CommandCommentPort commandCommentPort;
37-
private final LoadAttachmentPort loadAttachmentPort;
38-
private final CommandAttachmentPort commandAttachmentPort;
3936

4037
@Transactional
4138
@Override
@@ -54,23 +51,8 @@ public void editComment(Long memberId, Long commentId, EditCommentRequest reques
5451
@Transactional
5552
@Override
5653
public void deleteComment(Long memberId, Long commentId) {
57-
Member member = memberService.findActiveMember(memberId);
58-
Comment comment = commentService.findById(commentId);
59-
60-
if (comment.getMember().getMemberId().equals(member.getMemberId())) {
61-
if (loadAttachmentPort.exitsByCommentId(commentId)) {
62-
deleteAttachments(commentId);
63-
}
64-
commandCommentPort.deleteCommentWithTaskHistory(commentId);
65-
}else{
66-
throw new ApplicationException(CommentErrorCode.NOT_A_COMMENT_WRITER);
67-
}
68-
}
69-
70-
private void deleteAttachments(Long commentId) {
71-
Attachment attachment = loadAttachmentPort.findByCommentId(commentId)
72-
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_ATTACHMENT_NOT_FOUND));
73-
attachment.softDelete();
74-
commandAttachmentPort.save(attachment);
54+
memberService.findActiveMember(memberId);
55+
commentService.findById(commentId);
56+
commandCommentPort.deleteCommentWithTaskHistory(commentId);
7557
}
7658
}

src/main/java/clap/server/application/service/history/FindTaskHistoriesService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public FindTaskHistoryResponse findTaskHistories(Long memberId, Long taskId) {
3333
memberService.findActiveMember(memberId);
3434
Task task = loadTaskPort.findById(taskId)
3535
.orElseThrow(()-> new DomainException(TaskErrorCode.TASK_NOT_FOUND));
36-
//List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNotNull(task.getTaskId());
3736
List<TaskHistory> taskHistories = loadTaskHistoryPort.findAllTaskHistoriesByTaskId(task.getTaskId());
3837
return TaskHistoryResponseMapper.toFindTaskHistoryResponse(taskHistories);
3938
}

src/main/java/clap/server/application/service/task/FindTaskDetailsService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public FindTaskDetailsResponse findRequestedTaskDetails(final Long requesterId,
3131
memberService.findActiveMember(requesterId);
3232
Task task = loadTaskPort.findById(taskId)
3333
.orElseThrow(()-> new ApplicationException(TaskErrorCode.TASK_NOT_FOUND));
34-
List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNull(taskId);
34+
List<Attachment> attachments = loadAttachmentPort.findAllByTaskId(taskId);
3535
return TaskResponseMapper.toFindTaskDetailResponse(task, attachments);
3636
}
3737

@@ -40,7 +40,7 @@ public FindTaskDetailsForManagerResponse findTaskDetailsForManager(final Long re
4040
memberService.findActiveMember(requesterId);
4141
Task task = loadTaskPort.findById(taskId)
4242
.orElseThrow(() -> new ApplicationException(TaskErrorCode.TASK_NOT_FOUND));
43-
List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNull(taskId);
43+
List<Attachment> attachments = loadAttachmentPort.findAllByTaskId(taskId);
4444
return TaskResponseMapper.toFindTaskDetailForManagerResponse(task, attachments);
4545
}
4646
}

src/main/java/clap/server/application/service/task/UpdateTaskService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void updateAttachments(List<Long> attachmentIdsToDelete, List<MultipartF
138138
}
139139

140140
private List<Attachment> validateAndGetAttachments(List<Long> attachmentIdsToDelete, Task task) {
141-
List<Attachment> attachmentsOfTask = loadAttachmentPort.findAllByTaskIdAndCommentIsNullAndAttachmentId(task.getTaskId(), attachmentIdsToDelete);
141+
List<Attachment> attachmentsOfTask = loadAttachmentPort.findAllByTaskIdAndAttachmentId(task.getTaskId(), attachmentIdsToDelete);
142142
if (attachmentsOfTask.size() != attachmentIdsToDelete.size()) {
143143
throw new ApplicationException(TaskErrorCode.TASK_ATTACHMENT_NOT_FOUND);
144144
}

0 commit comments

Comments
 (0)