Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package clap.server.adapter.inbound.web.notification;

import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "알림 읽음 처리")
@WebAdapter
@RestController
@RequestMapping("/api/notification")
@RequiredArgsConstructor
public class ManagementNotificationController {

private final UpdateNotificationUsecase updateNotificationUsecase;

@Operation(summary = "알림 목록에서 한 개 눌렀을 때 읽음 처리")
@Parameter(name = "notificationId", description = "알림 고유 ID", required = true, in = ParameterIn.PATH)
@PatchMapping("/{notificationId}")
public void updateNotificationIsRead(@PathVariable Long notificationId) {
updateNotificationUsecase.updateNotification(notificationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;

@PersistenceAdapter
@RequiredArgsConstructor
public class NotificationPersistenceAdapter implements LoadNotificationPort, CommandNotificationPort {
Expand All @@ -20,6 +23,12 @@ public class NotificationPersistenceAdapter implements LoadNotificationPort, Com
private final NotificationPersistenceMapper notificationPersistenceMapper;


@Override
public Optional<Notification> findById(Long notificationId) {
return notificationRepository.findById(notificationId)
.map(notificationPersistenceMapper::toDomain);
}

@Override
public Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
Page<Notification> notificationList = notificationRepository.findAllByReceiver_MemberId(receiverId, pageable)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package clap.server.application.port.inbound.notification;

public interface UpdateNotificationUsecase {
void updateNotification(Long notificationId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package clap.server.application.port.outbound.notification;

import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
import clap.server.domain.model.notification.Notification;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;


public interface LoadNotificationPort {

Optional<Notification> findById(Long notificationId);

Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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;

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ public Notification(Task task, NotificationType type, Member receiver, String me
this.message = message;
this.isRead = false;
}

public void updateNotificationIsRead() {
this.isRead = true;
}

public static Notification createTaskNotification(Task task, Member reviewer, NotificationType type) {
return Notification.builder()
.task(task)
.type(type)
.receiver(reviewer)
.message(null)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package clap.server.exception.code;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

@Getter
@RequiredArgsConstructor
public enum NotificationErrorCode implements BaseErrorCode {

NOTIFICATION_NOT_FOUND(HttpStatus.NOT_FOUND, "NOTIFICATION_001", "알림을 찾을 수 없습니다"),
;

private final HttpStatus httpStatus;
private final String customCode;
private final String message;
}
Loading