Skip to content

Commit 47082c4

Browse files
committed
CLAP-136 Feature: 알림 한 개 읽음 처리 기능 구현
1 parent 0408482 commit 47082c4

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clap.server.adapter.inbound.web.notification;
2+
3+
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
4+
import clap.server.common.annotation.architecture.WebAdapter;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.Parameter;
7+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
8+
import io.swagger.v3.oas.annotations.tags.Tag;
9+
import lombok.RequiredArgsConstructor;
10+
import org.springframework.web.bind.annotation.PatchMapping;
11+
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
@Tag(name = "알림 읽음 처리")
16+
@WebAdapter
17+
@RestController
18+
@RequestMapping("/api/notification")
19+
@RequiredArgsConstructor
20+
public class ManagementNotificationController {
21+
22+
private final UpdateNotificationUsecase updateNotificationUsecase;
23+
24+
@Operation(summary = "알림 목록에서 한 개 눌렀을 때 읽음 처리")
25+
@Parameter(name = "notificationId", description = "알림 고유 ID", required = true, in = ParameterIn.PATH)
26+
@PatchMapping("/{notificationId}")
27+
public void updateNotificationIsRead(@PathVariable Long notificationId) {
28+
updateNotificationUsecase.updateNotification(notificationId);
29+
}
30+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.springframework.data.domain.Page;
1313
import org.springframework.data.domain.Pageable;
1414

15+
import java.util.List;
16+
import java.util.Optional;
17+
1518
@PersistenceAdapter
1619
@RequiredArgsConstructor
1720
public class NotificationPersistenceAdapter implements LoadNotificationPort, CommandNotificationPort {
@@ -20,6 +23,12 @@ public class NotificationPersistenceAdapter implements LoadNotificationPort, Com
2023
private final NotificationPersistenceMapper notificationPersistenceMapper;
2124

2225

26+
@Override
27+
public Optional<Notification> findById(Long notificationId) {
28+
return notificationRepository.findById(notificationId)
29+
.map(notificationPersistenceMapper::toDomain);
30+
}
31+
2332
@Override
2433
public Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
2534
Page<Notification> notificationList = notificationRepository.findAllByReceiver_MemberId(receiverId, pageable)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package clap.server.application.port.inbound.notification;
2+
3+
public interface UpdateNotificationUsecase {
4+
void updateNotification(Long notificationId);
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package clap.server.application.port.outbound.notification;
22

33
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
4+
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
5+
import clap.server.domain.model.notification.Notification;
46
import org.springframework.data.domain.Page;
57
import org.springframework.data.domain.Pageable;
68

9+
import java.util.List;
10+
import java.util.Optional;
11+
712

813
public interface LoadNotificationPort {
14+
15+
Optional<Notification> findById(Long notificationId);
16+
917
Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
1018
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clap.server.application.service.notification;
2+
3+
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
4+
import clap.server.adapter.outbound.persistense.repository.notification.NotificationRepository;
5+
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
6+
import clap.server.application.port.outbound.notification.CommandNotificationPort;
7+
import clap.server.application.port.outbound.notification.LoadNotificationPort;
8+
import clap.server.common.annotation.architecture.ApplicationService;
9+
import clap.server.domain.model.notification.Notification;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.transaction.annotation.Transactional;
12+
13+
import java.util.Optional;
14+
15+
@ApplicationService
16+
@RequiredArgsConstructor
17+
public class UpdateNotificationService implements UpdateNotificationUsecase {
18+
19+
private final LoadNotificationPort loadNotificationPort;
20+
private final CommandNotificationPort commandNotificationPort;
21+
22+
23+
@Transactional
24+
@Override
25+
public void updateNotification(Long notificationId) {
26+
Notification notification = loadNotificationPort.findById(notificationId).get();
27+
notification.updateNotificationIsRead();
28+
commandNotificationPort.save(notification);
29+
}
30+
}

src/main/java/clap/server/domain/model/notification/Notification.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public Notification(Task task, NotificationType type, Member receiver, String me
3434
this.message = message;
3535
this.isRead = false;
3636
}
37+
38+
public void updateNotificationIsRead() {
39+
this.isRead = true;
40+
}
3741
}

0 commit comments

Comments
 (0)