Skip to content

Commit 7c44437

Browse files
committed
CLAP-393 Fix : 사용자가 작업 취소시 해당 알림 삭제 처리
1 parent 47cfcbf commit 7c44437

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ Slice<NotificationEntity> findAllByReceiver_MemberIdOrderByCreatedAtDesc(
2727
"AND n.task.isDeleted = false")
2828
List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);
2929

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

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

0 commit comments

Comments
 (0)