Skip to content

Commit 2bcbfc6

Browse files
authored
Merge pull request #508 from TaskFlow-CLAP/CLAP-393
CLAP-393 알림 확인 및 조회 에러 해결
2 parents af8f272 + 820828b commit 2bcbfc6

File tree

9 files changed

+53
-16
lines changed

9 files changed

+53
-16
lines changed

src/main/java/clap/server/adapter/outbound/api/email/EmailTemplateBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public EmailTemplate createWebhookTemplate(PushNotificationTemplate request, Str
2424
switch (request.notificationType()) {
2525
case TASK_REQUESTED:
2626
templateName = "task-request";
27-
subject = "[TaskFlow] 신규 작업 "+ request.taskName()+ " 요청되었습니다.";
27+
subject = "[TaskFlow] 신규 작업 "+ request.taskName()+ " 요청되었습니다.";
2828
context.setVariable("taskDetailUrl", taskDetailUrl);
2929
context.setVariable("receiverName", request.senderName());
3030
context.setVariable("title", request.taskName());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public List<Notification> findNotificationsByMemberId(final Long memberId) {
4242
.collect(Collectors.toList());
4343
}
4444

45+
@Override
46+
public List<Notification> findNotificationsByTaskId(Long taskId) {
47+
return notificationRepository.findByTask_TaskId(taskId)
48+
.stream().map(notificationPersistenceMapper::toDomain)
49+
.collect(Collectors.toList());
50+
}
51+
4552
@Override
4653
public Integer countNotification(final Long memberId) {
4754
return notificationRepository.countByIsReadFalseAndReceiver_MemberId(memberId);
@@ -51,4 +58,9 @@ public Integer countNotification(final Long memberId) {
5158
public void save(final Notification notification) {
5259
notificationRepository.save(notificationPersistenceMapper.toEntity(notification));
5360
}
61+
62+
@Override
63+
public void delete(Notification notification) {
64+
notificationRepository.delete(notificationPersistenceMapper.toEntity(notification));
65+
}
5466
}

src/main/java/clap/server/adapter/outbound/persistense/repository/notification/NotificationRepository.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
public interface NotificationRepository extends JpaRepository<NotificationEntity, Long> {
1717

1818
@Query("SELECT n FROM NotificationEntity n " +
19-
"JOIN FETCH n.task t " +
20-
"JOIN FETCH n.receiver r " +
2119
"WHERE n.receiver.memberId = :receiverId " +
22-
"AND t.isDeleted = false " +
20+
"AND n.task.isDeleted = false " +
2321
"ORDER BY n.createdAt DESC")
2422
Slice<NotificationEntity> findAllByReceiver_MemberIdOrderByCreatedAtDesc(
2523
@Param("receiverId") Long receiverId, Pageable pageable);
2624

25+
@Query("SELECT n FROM NotificationEntity n " +
26+
"WHERE n.receiver.memberId = :receiverId " +
27+
"AND n.task.isDeleted = false")
2728
List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);
2829

30+
List<NotificationEntity> findByTask_TaskId(Long taskId);
31+
2932
Integer countByIsReadFalseAndReceiver_MemberId(Long memberId);
3033
}

src/main/java/clap/server/application/port/outbound/notification/CommandNotificationPort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
public interface CommandNotificationPort {
77
void save(Notification notification);
8+
9+
void delete(Notification notification);
810
}

src/main/java/clap/server/application/port/outbound/notification/LoadNotificationPort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ public interface LoadNotificationPort {
1616

1717
List<Notification> findNotificationsByMemberId(Long memberId);
1818

19+
List<Notification> findNotificationsByTaskId(Long taskId);
20+
1921
Integer countNotification(Long memberId);
2022
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ public void save(Long memberId, Long taskId, CreateCommentRequest request) {
5858

5959
Member processor = task.getProcessor();
6060
Member requester = task.getRequester();
61-
if (Objects.equals(member.getMemberId(), requester.getMemberId())) {
62-
publishNotification(processor, task, request.content(), member.getNickname());
63-
} else {
64-
publishNotification(requester, task, request.content(), member.getNickname());
65-
}
61+
Member receiver = Objects.equals(member.getMemberId(), requester.getMemberId()) ? processor : requester;
6662

63+
if (receiver != null) {
64+
publishNotification(receiver, task, request.content(), member.getNickname());
65+
}
6766
}
6867

6968
@Transactional
@@ -85,10 +84,11 @@ public void saveCommentAttachment(Long memberId, Long taskId, MultipartFile file
8584

8685
Member processor = task.getProcessor();
8786
Member requester = task.getRequester();
88-
if (member.getMemberInfo().getRole() == requester.getMemberInfo().getRole()) {
89-
publishNotification(processor, task, fileName + "(첨부파일)", requester.getNickname());
90-
} else {
91-
publishNotification(requester, task, fileName + "(첨부파일)", processor.getNickname());
87+
Member receiver = Objects.equals(member.getMemberId(), requester.getMemberId()) ? processor : requester;
88+
String senderNickname = Objects.equals(member.getMemberId(), requester.getMemberId()) ? requester.getNickname() : processor.getNickname();
89+
90+
if (receiver != null) {
91+
publishNotification(receiver, task, fileName + "(첨부파일)", senderNickname);
9292
}
9393

9494
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@
22

33
import clap.server.application.port.inbound.domain.TaskService;
44
import clap.server.application.port.inbound.task.CancelTaskUsecase;
5+
import clap.server.application.port.outbound.notification.CommandNotificationPort;
6+
import clap.server.application.port.outbound.notification.LoadNotificationPort;
57
import clap.server.common.annotation.architecture.ApplicationService;
8+
import clap.server.domain.model.notification.Notification;
69
import clap.server.domain.model.task.Task;
710
import lombok.RequiredArgsConstructor;
811
import org.springframework.transaction.annotation.Transactional;
912

10-
import java.util.Objects;
13+
import java.util.List;
1114

1215

1316
@ApplicationService
1417
@RequiredArgsConstructor
1518
@Transactional
1619
public class CancelTaskService implements CancelTaskUsecase {
1720
private final TaskService taskService;
21+
private final LoadNotificationPort loadNotificationPort;
22+
private final CommandNotificationPort commandNotificationPort;
1823

1924
@Override
2025
public void cancleTask(Long taskId, Long memberId) {
2126
Task task = taskService.findById(taskId);
27+
deleteNotification(task.getTaskId());
2228
task.cancelTask(memberId);
2329
taskService.upsert(task);
2430
}
31+
32+
private void deleteNotification(Long taskId) {
33+
List<Notification> notificationList = loadNotificationPort.findNotificationsByTaskId(taskId);
34+
35+
notificationList.forEach(commandNotificationPort::delete);
36+
}
37+
2538
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import org.springframework.web.multipart.MultipartFile;
3434

3535
import java.util.List;
36+
import java.util.Objects;
37+
import java.util.stream.Collectors;
38+
import java.util.stream.Stream;
3639

3740
import static clap.server.domain.policy.task.TaskPolicyConstants.TASK_MAX_FILE_COUNT;
3841
import static clap.server.domain.policy.task.TaskPolicyConstants.TASK_UPDATABLE_STATUS;
@@ -89,7 +92,7 @@ public void updateTaskStatus(Long memberId, Long taskId, TaskStatus taskStatus)
8992
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, task, taskStatus.getDescription(), null, null);
9093
commandTaskHistoryPort.save(taskHistory);
9194

92-
List<Member> receivers = List.of(task.getRequester(), task.getProcessor());
95+
List<Member> receivers = List.of(task.getRequester());
9396
publishNotification(receivers, updateTask, NotificationType.STATUS_SWITCHED, String.valueOf(updateTask.getTaskStatus()));
9497
}
9598
}
@@ -107,7 +110,7 @@ public void updateTaskProcessor(Long taskId, Long memberId, UpdateTaskProcessorR
107110
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_CHANGED, task, null, processor, null);
108111
commandTaskHistoryPort.save(taskHistory);
109112

110-
List<Member> receivers = List.of(updateTask.getRequester(), updateTask.getProcessor());
113+
List<Member> receivers = List.of(updateTask.getRequester());
111114
publishNotification(receivers, updateTask, NotificationType.PROCESSOR_CHANGED, processor.getNickname());
112115
}
113116

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table notification
2+
modify task_title varchar(30) not null;

0 commit comments

Comments
 (0)