-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathReadNotificationService.java
More file actions
41 lines (34 loc) · 1.65 KB
/
ReadNotificationService.java
File metadata and controls
41 lines (34 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package clap.server.application.service.notification;
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
import clap.server.application.port.outbound.notification.CommandNotificationPort;
import clap.server.application.port.outbound.notification.LoadNotificationPort;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.notification.Notification;
import clap.server.exception.ApplicationException;
import clap.server.exception.code.NotificationErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ApplicationService
@RequiredArgsConstructor
public class ReadNotificationService implements UpdateNotificationUsecase {
private final LoadNotificationPort loadNotificationPort;
private final CommandNotificationPort commandNotificationPort;
@Transactional
@Override
public void updateNotification(Long notificationId) {
Notification notification = loadNotificationPort.findById(notificationId)
.orElseThrow(() -> new ApplicationException(NotificationErrorCode.NOTIFICATION_NOT_FOUND));
notification.updateNotificationIsRead();
commandNotificationPort.save(notification);
}
@Transactional
@Override
public void updateAllNotification(Long memberId) {
List<Notification> notificationList = loadNotificationPort.findNotificationsByMemberId(memberId);
for (Notification notification : notificationList) {
notification.updateNotificationIsRead();
commandNotificationPort.save(notification);
}
}
}