diff --git a/src/main/java/com/umc/naoman/domain/notification/controller/NotificationController.java b/src/main/java/com/umc/naoman/domain/notification/controller/NotificationController.java index 186b024c..8ad8e62c 100644 --- a/src/main/java/com/umc/naoman/domain/notification/controller/NotificationController.java +++ b/src/main/java/com/umc/naoman/domain/notification/controller/NotificationController.java @@ -5,12 +5,17 @@ import com.umc.naoman.domain.notification.dto.NotificationRequest; import com.umc.naoman.domain.notification.dto.NotificationResponse; import com.umc.naoman.domain.notification.entity.Notification; +import com.umc.naoman.domain.notification.service.FcmService; import com.umc.naoman.domain.notification.service.NotificationService; import com.umc.naoman.global.result.ResultResponse; import com.umc.naoman.global.result.code.NotificationResultCode; import com.umc.naoman.global.security.annotation.LoginMember; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -24,13 +29,25 @@ @RestController @RequiredArgsConstructor @RequestMapping("/notifications") +@Tag(name = "알림 관련 API", description = " 알림 전체 목록 조희, fcm 토큰 업로드, 알림 1개 삭제, 알림 전체 삭제, 읽지 않은 알림 유무, 내 알람 전체 읽음 처리를 하는 API입니다.") public class NotificationController { private final NotificationService notificationService; + private final FcmService fcmService; + private final NotificationConverter notificationConverter; @PostMapping("/token") + @Operation( + summary = "fcm 토큰 업로드", + description = "안드로이드가 fcm 토큰을 서버에 업로드하는 API입니다.", + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + content = @Content( + schema = @Schema(implementation = NotificationRequest.FcmToken.class) + ) + ) + ) public ResultResponse registerFcmToken(@RequestBody NotificationRequest.FcmToken fcmToken, @LoginMember Member member){ - + fcmService.saveFcmToken(member, fcmToken.getToken()); return ResultResponse.of(NotificationResultCode.REGISTER_FCM_TOKEN,null); } @@ -39,39 +56,54 @@ public ResultResponse registerFcmToken(@RequestBody NotificationRequest.Fc @Parameter(name = "page", description = "조회할 페이지를 입력해 주세요.(0번부터 시작)"), @Parameter(name = "size", description = "한 페이지에 나타낼 알림 개수를 입력해주세요.") }) - public ResultResponse getNotifications(@LoginMember Member member, + @Operation(summary = "자신의 모든 알림 조회", description = "자신의 모든 알림을 조회하는 API입니다.") + public ResultResponse getNotificationList(@LoginMember Member member, @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) @Parameter(hidden = true) Pageable pageable){ Page notificationPage = notificationService.getNotificationList(member, pageable); return ResultResponse.of(NotificationResultCode.GET_MY_NOTIFICATION, - NotificationConverter.toNotificationInfo(notificationPage)); + notificationConverter.toPagedNotificationInfo(notificationPage)); } @GetMapping("/unread") - public ResultResponse getIsUnread(@LoginMember Member member){ + @Operation(summary = "읽지 않은 알림 유무 조회", + description = "읽지 않은 알림 유무 조회하는 API입니다.", + parameters = {}) + public ResultResponse getIsUnread(@LoginMember Member member){ List notificationList = notificationService.isUnreadNotification(member); return ResultResponse.of(NotificationResultCode.CHECK_MY_UNREAD_NOTIFICATION, - NotificationConverter.toUnreadNotification(notificationList)); + notificationConverter.toIsUnread(notificationList)); } @PostMapping("/acknowledgements") + @Operation(summary = "모든 알림 읽음 처리", + description = "자신의 모든 알림을 읽음 처리하는 API입니다.", + parameters = {}) public ResultResponse setMyNotificationRead(@LoginMember Member member){ List notificationList = notificationService.setMyNotificationRead(member); return ResultResponse.of(NotificationResultCode.READ_ALL_MY_NOTIFICATION, - NotificationConverter.toNotificationAcknowledgedCount(notificationList)); + notificationConverter.toNotificationAcknowledgedCount(notificationList)); } @DeleteMapping("/{notificationId}") + @Operation(summary = "특정 알림 삭제", + description = "특정 알림을 삭제하는 API입니다.", + parameters = { + @Parameter(name = "notificationId", description = "삭제할 알림의 Id", required = true, schema = @Schema(type = "long")) + }) public ResultResponse deleteNotification(@PathVariable Long notificationId, @LoginMember Member member){ long deletedCount = notificationService.deleteNotification(member,notificationId); return ResultResponse.of(NotificationResultCode.DELETE_MY_NOTIFICATION, - NotificationConverter.toNotificationAcknowledgedCount(deletedCount)); + notificationConverter.toNotificationAcknowledgedCount(deletedCount)); } @DeleteMapping + @Operation(summary = "모든 알림 삭제", + description = "자신의 모든 알림을 삭제하는 API입니다.", + parameters = {}) public ResultResponse deleteAllNotification(@LoginMember Member member){ long deletedCount = notificationService.deleteNotificationAll(member); return ResultResponse.of(NotificationResultCode.DELETE_MY_NOTIFICATION, - NotificationConverter.toNotificationDeletedCount(deletedCount)); + notificationConverter.toNotificationDeletedCount(deletedCount)); } } diff --git a/src/main/java/com/umc/naoman/domain/notification/converter/NotificationConverter.java b/src/main/java/com/umc/naoman/domain/notification/converter/NotificationConverter.java index 146c5e9d..50812760 100644 --- a/src/main/java/com/umc/naoman/domain/notification/converter/NotificationConverter.java +++ b/src/main/java/com/umc/naoman/domain/notification/converter/NotificationConverter.java @@ -6,13 +6,15 @@ import com.umc.naoman.domain.notification.entity.DeviceToken; import com.umc.naoman.domain.notification.entity.Notification; import org.springframework.data.domain.Page; +import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors; +@Component public class NotificationConverter { - public static NotificationResponse.NotificationInfo notificationInfo(Notification notification){ + public NotificationResponse.NotificationInfo toNotificationInfo(Notification notification){ return NotificationResponse.NotificationInfo.builder() .body(notification.getMessage()) .createdAt(notification.getCreatedAt()) @@ -20,10 +22,10 @@ public static NotificationResponse.NotificationInfo notificationInfo(Notificatio .url(notification.makeNotificationInfoURL()) //다형성으로 각기 다른 알림이 적절한 URL 만들도록 오버라이딩. .build(); } - public static NotificationResponse.PagedNotificationInfo toNotificationInfo( + public NotificationResponse.PagedNotificationInfo toPagedNotificationInfo( Page notificationList){ List notificationInfoList - = notificationList.stream().map(NotificationConverter::notificationInfo).collect(Collectors.toList()); + = notificationList.stream().map(this::toNotificationInfo).collect(Collectors.toList()); return NotificationResponse.PagedNotificationInfo.builder() .isLast(notificationList.isLast()) @@ -34,30 +36,30 @@ public static NotificationResponse.PagedNotificationInfo toNotificationInfo( .build(); } - public static NotificationResponse.UnreadNotification toUnreadNotification(List notificationList){ - return NotificationResponse.UnreadNotification.builder() + public NotificationResponse.IsUnread toIsUnread(List notificationList){ + return NotificationResponse.IsUnread.builder() .isUnread(!notificationList.isEmpty()) .build(); } - public static NotificationResponse.NotificationAcknowledgeCount toNotificationAcknowledgedCount(List notificationList){ + public NotificationResponse.NotificationAcknowledgeCount toNotificationAcknowledgedCount(List notificationList){ return NotificationResponse.NotificationAcknowledgeCount.builder() .acknowledgedCount((long)notificationList.size()) .build(); } - public static NotificationResponse.NotificationAcknowledgeCount toNotificationAcknowledgedCount(Long updateCount){ + public NotificationResponse.NotificationAcknowledgeCount toNotificationAcknowledgedCount(Long updateCount){ return NotificationResponse.NotificationAcknowledgeCount.builder() .acknowledgedCount(updateCount) .build(); } - public static NotificationResponse.NotificationDeletedCount toNotificationDeletedCount(Long updateCount){ + public NotificationResponse.NotificationDeletedCount toNotificationDeletedCount(Long updateCount){ return NotificationResponse.NotificationDeletedCount.builder() .deletedCount(updateCount) .build(); } - public static DeviceToken toDeviceToken(Member member, NotificationRequest.FcmToken fcmToken){ + public DeviceToken toDeviceToken(Member member, NotificationRequest.FcmToken fcmToken){ return DeviceToken.builder() .member(member) .fcmToken(fcmToken.getToken()) diff --git a/src/main/java/com/umc/naoman/domain/notification/dto/NotificationResponse.java b/src/main/java/com/umc/naoman/domain/notification/dto/NotificationResponse.java index 6e1dccbc..54c6fc35 100644 --- a/src/main/java/com/umc/naoman/domain/notification/dto/NotificationResponse.java +++ b/src/main/java/com/umc/naoman/domain/notification/dto/NotificationResponse.java @@ -38,7 +38,7 @@ public static class NotificationInfo { @Getter @NoArgsConstructor @AllArgsConstructor - public static class UnreadNotification { + public static class IsUnread { Boolean isUnread; } diff --git a/src/main/java/com/umc/naoman/domain/notification/service/FcmService.java b/src/main/java/com/umc/naoman/domain/notification/service/FcmService.java index 37ee41e7..3d1cf515 100644 --- a/src/main/java/com/umc/naoman/domain/notification/service/FcmService.java +++ b/src/main/java/com/umc/naoman/domain/notification/service/FcmService.java @@ -1,5 +1,7 @@ package com.umc.naoman.domain.notification.service; +import com.umc.naoman.domain.member.entity.Member; + public interface FcmService { - void saveFcmToken(Long memberId, String fcmToken); + void saveFcmToken(Member member, String fcmToken); } diff --git a/src/main/java/com/umc/naoman/domain/notification/service/FcmServiceImpl.java b/src/main/java/com/umc/naoman/domain/notification/service/FcmServiceImpl.java index de8e0e75..2fe7a04b 100644 --- a/src/main/java/com/umc/naoman/domain/notification/service/FcmServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/notification/service/FcmServiceImpl.java @@ -1,5 +1,6 @@ package com.umc.naoman.domain.notification.service; +import com.umc.naoman.domain.member.entity.Member; import com.umc.naoman.domain.notification.entity.DeviceToken; import com.umc.naoman.domain.notification.repository.FcmTokenRepository; import lombok.RequiredArgsConstructor; @@ -13,10 +14,9 @@ public class FcmServiceImpl implements FcmService{ private final FcmTokenRepository fcmTokenRepository; @Override - public void saveFcmToken(Long memberId, String fcmToken) { - //멤버 리파지토리 개발 후 수정해야됨 + public void saveFcmToken(Member member, String fcmToken) { DeviceToken deviceToken = DeviceToken.builder() - .member(null) + .member(member) .fcmToken(fcmToken) .build(); fcmTokenRepository.save(deviceToken);