Skip to content

Commit 320aac6

Browse files
authored
Merge pull request #103 from TaskFlow-CLAP/CLAP-136
CLAP-136 알림 한 개 읽음 처리 기능 구현
2 parents 4342b51 + 7d37d90 commit 320aac6

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package clap.server.application.service.notification;
2+
3+
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
4+
import clap.server.application.port.outbound.notification.CommandNotificationPort;
5+
import clap.server.application.port.outbound.notification.LoadNotificationPort;
6+
import clap.server.common.annotation.architecture.ApplicationService;
7+
import clap.server.domain.model.notification.Notification;
8+
import clap.server.exception.ApplicationException;
9+
import clap.server.exception.code.NotificationErrorCode;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.transaction.annotation.Transactional;
12+
13+
@ApplicationService
14+
@RequiredArgsConstructor
15+
public class ReadNotificationService implements UpdateNotificationUsecase {
16+
17+
private final LoadNotificationPort loadNotificationPort;
18+
private final CommandNotificationPort commandNotificationPort;
19+
20+
21+
@Transactional
22+
@Override
23+
public void updateNotification(Long notificationId) {
24+
Notification notification = loadNotificationPort.findById(notificationId)
25+
.orElseThrow(() -> new ApplicationException(NotificationErrorCode.NOTIFICATION_NOT_FOUND));
26+
notification.updateNotificationIsRead();
27+
commandNotificationPort.save(notification);
28+
}
29+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,17 @@ 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+
}
41+
42+
public static Notification createTaskNotification(Task task, Member reviewer, NotificationType type) {
43+
return Notification.builder()
44+
.task(task)
45+
.type(type)
46+
.receiver(reviewer)
47+
.message(null)
48+
.build();
49+
}
3750
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package clap.server.exception.code;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.http.HttpStatus;
6+
7+
@Getter
8+
@RequiredArgsConstructor
9+
public enum NotificationErrorCode implements BaseErrorCode {
10+
11+
NOTIFICATION_NOT_FOUND(HttpStatus.NOT_FOUND, "NOTIFICATION_001", "알림을 찾을 수 없습니다"),
12+
;
13+
14+
private final HttpStatus httpStatus;
15+
private final String customCode;
16+
private final String message;
17+
}

0 commit comments

Comments
 (0)