From 031bd9fc50d7233f5161c04c33bf3dd70544200b Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Mon, 5 Aug 2024 21:31:23 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=EC=97=90=20=EC=8A=A4=EC=9B=A8?= =?UTF-8?q?=EA=B1=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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..c877408e 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 @@ -9,8 +9,12 @@ 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,10 +28,20 @@ @RestController @RequiredArgsConstructor @RequestMapping("/notifications") +@Tag(name = "알림 관련 API", description = " 알림 전체 목록 조희, fcm 토큰 업로드, 알림 1개 삭제, 알림 전체 삭제, 읽지 않은 알림 유무, 내 알람 전체 읽음 처리를 하는 API입니다.") public class NotificationController { private final NotificationService notificationService; @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){ @@ -39,6 +53,7 @@ public ResultResponse registerFcmToken(@RequestBody NotificationRequest.Fc @Parameter(name = "page", description = "조회할 페이지를 입력해 주세요.(0번부터 시작)"), @Parameter(name = "size", description = "한 페이지에 나타낼 알림 개수를 입력해주세요.") }) + @Operation(summary = "자신의 모든 알림 조회", description = "자신의 모든 알림을 조회하는 API입니다.") public ResultResponse getNotifications(@LoginMember Member member, @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) @Parameter(hidden = true) Pageable pageable){ @@ -48,6 +63,9 @@ public ResultResponse getNotificatio } @GetMapping("/unread") + @Operation(summary = "읽지 않은 알림 유무 조회", + description = "읽지 않은 알림 유무 조회하는 API입니다.", + parameters = {}) public ResultResponse getIsUnread(@LoginMember Member member){ List notificationList = notificationService.isUnreadNotification(member); return ResultResponse.of(NotificationResultCode.CHECK_MY_UNREAD_NOTIFICATION, @@ -55,6 +73,9 @@ public ResultResponse getIsUnread(@Logi } @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, @@ -62,6 +83,11 @@ public ResultResponse setMyNo } @DeleteMapping("/{notificationId}") + @Operation(summary = "특정 알림 1개 삭제", + description = "특정 알림 1개를 삭제하는 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); @@ -69,6 +95,9 @@ public ResultResponse deleteN 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, From 88f143fe0c4f2d1874a32d69105be76498155410 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Mon, 5 Aug 2024 23:16:41 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refact=20:=20=EC=BB=A8=EB=B2=84=ED=84=B0=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=EB=A1=9C=20=EC=B9=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 21 +++++++++++-------- .../converter/NotificationConverter.java | 20 ++++++++++-------- .../dto/NotificationResponse.java | 2 +- .../notification/service/FcmService.java | 4 +++- .../notification/service/FcmServiceImpl.java | 6 +++--- 5 files changed, 30 insertions(+), 23 deletions(-) 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 c877408e..442f98f6 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,6 +5,7 @@ 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; @@ -31,6 +32,8 @@ @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( @@ -44,7 +47,7 @@ public class NotificationController { ) public ResultResponse registerFcmToken(@RequestBody NotificationRequest.FcmToken fcmToken, @LoginMember Member member){ - + fcmService.saveFcmToken(member, fcmToken.getToken()); return ResultResponse.of(NotificationResultCode.REGISTER_FCM_TOKEN,null); } @@ -59,17 +62,17 @@ public ResultResponse getNotificatio @Parameter(hidden = true) Pageable pageable){ Page notificationPage = notificationService.getNotificationList(member, pageable); return ResultResponse.of(NotificationResultCode.GET_MY_NOTIFICATION, - NotificationConverter.toNotificationInfo(notificationPage)); + notificationConverter.toNotificationInfo(notificationPage)); } @GetMapping("/unread") @Operation(summary = "읽지 않은 알림 유무 조회", description = "읽지 않은 알림 유무 조회하는 API입니다.", parameters = {}) - public ResultResponse getIsUnread(@LoginMember Member member){ + 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") @@ -79,12 +82,12 @@ public ResultResponse getIsUnread(@Logi 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 = "특정 알림 1개 삭제", - description = "특정 알림 1개를 삭제하는 API입니다.", + @Operation(summary = "특정 알림 삭제", + description = "특정 알림을 삭제하는 API입니다.", parameters = { @Parameter(name = "notificationId", description = "삭제할 알림의 Id", required = true, schema = @Schema(type = "long")) }) @@ -92,7 +95,7 @@ public ResultResponse deleteN @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 = "모든 알림 삭제", @@ -101,6 +104,6 @@ public ResultResponse deleteN 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..4b376230 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 notificationInfo(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 toNotificationInfo( Page notificationList){ List notificationInfoList - = notificationList.stream().map(NotificationConverter::notificationInfo).collect(Collectors.toList()); + = notificationList.stream().map(this::notificationInfo).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); From a45d8175c8f209e787b53379f19642a0f689fc3e Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Wed, 7 Aug 2024 17:37:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refact=20:=20=EC=95=8C=EB=A6=BC=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC,=20=EC=95=8C=EB=A6=BC=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=84=ED=84=B0=20=ED=95=A8=EC=88=98=EB=AA=85=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/controller/NotificationController.java | 4 ++-- .../notification/converter/NotificationConverter.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) 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 442f98f6..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 @@ -57,12 +57,12 @@ public ResultResponse registerFcmToken(@RequestBody NotificationRequest.Fc @Parameter(name = "size", description = "한 페이지에 나타낼 알림 개수를 입력해주세요.") }) @Operation(summary = "자신의 모든 알림 조회", description = "자신의 모든 알림을 조회하는 API입니다.") - public ResultResponse getNotifications(@LoginMember Member member, + 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") 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 4b376230..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 @@ -14,7 +14,7 @@ @Component public class NotificationConverter { - public NotificationResponse.NotificationInfo notificationInfo(Notification notification){ + public NotificationResponse.NotificationInfo toNotificationInfo(Notification notification){ return NotificationResponse.NotificationInfo.builder() .body(notification.getMessage()) .createdAt(notification.getCreatedAt()) @@ -22,10 +22,10 @@ public NotificationResponse.NotificationInfo notificationInfo(Notification notif .url(notification.makeNotificationInfoURL()) //다형성으로 각기 다른 알림이 적절한 URL 만들도록 오버라이딩. .build(); } - public NotificationResponse.PagedNotificationInfo toNotificationInfo( + public NotificationResponse.PagedNotificationInfo toPagedNotificationInfo( Page notificationList){ List notificationInfoList - = notificationList.stream().map(this::notificationInfo).collect(Collectors.toList()); + = notificationList.stream().map(this::toNotificationInfo).collect(Collectors.toList()); return NotificationResponse.PagedNotificationInfo.builder() .isLast(notificationList.isLast())