diff --git a/src/main/java/org/sopt/app/application/notification/NotificationService.java b/src/main/java/org/sopt/app/application/notification/NotificationService.java index 08ee0e21..6c662706 100644 --- a/src/main/java/org/sopt/app/application/notification/NotificationService.java +++ b/src/main/java/org/sopt/app/application/notification/NotificationService.java @@ -31,6 +31,12 @@ public Notification findNotification(User user, String notificationId) { return notificationRepository.findByNotificationIdAndUserId(notificationId, user.getId()) .orElseThrow(() -> new BadRequestException(ErrorCode.NOTIFICATION_NOT_FOUND.getMessage())); } + @Transactional(readOnly = true) + @Deprecated + public Notification findNotificationDeprecated(User user, Long notificationId) { + return notificationRepository.findByIdAndUserId(notificationId, user.getId()) + .orElseThrow(() -> new BadRequestException(ErrorCode.NOTIFICATION_NOT_FOUND.getMessage())); + } @Transactional(readOnly = true) public List findNotificationList(User user, Pageable pageable) { @@ -78,6 +84,30 @@ public void updateNotificationIsRead(User user, String notificationId) { updateSingleNotificationIsRead(user, notificationId); } } + @Transactional + @Deprecated + public void updateNotificationIsReadDeprecated(User user, Long notificationId) { + if (Objects.isNull(notificationId)) { + updateAllNotificationIsRead(user); + } else { + updateSingleNotificationIsReadDeprecated(user, notificationId); + } + } + + private void updateSingleNotificationIsRead(User user, String notificationId) { + val notification = notificationRepository.findByNotificationIdAndUserId(notificationId, user.getId()) + .orElseThrow(() -> new BadRequestException(ErrorCode.NOTIFICATION_NOT_FOUND.getMessage())); + notification.updateIsRead(); + notificationRepository.save(notification); + } + + @Deprecated + private void updateSingleNotificationIsReadDeprecated(User user, Long notificationId) { + val notification = notificationRepository.findByIdAndUserId(notificationId, user.getId()) + .orElseThrow(() -> new BadRequestException(ErrorCode.NOTIFICATION_NOT_FOUND.getMessage())); + notification.updateIsRead(); + notificationRepository.save(notification); + } private void updateAllNotificationIsRead(User user) { val notificationList = notificationRepository.findAllByUserId(user.getId()); @@ -90,13 +120,6 @@ private void updateAllNotificationIsRead(User user) { notificationRepository.saveAll(readNotificationList); } - private void updateSingleNotificationIsRead(User user, String notificationId) { - val notification = notificationRepository.findByNotificationIdAndUserId(notificationId, user.getId()) - .orElseThrow(() -> new BadRequestException(ErrorCode.NOTIFICATION_NOT_FOUND.getMessage())); - notification.updateIsRead(); - notificationRepository.save(notification); - } - @Transactional(readOnly = true) public Boolean getNotificationConfirmStatus(User user) { val notificationList = notificationRepository.findAllByUserId(user.getId()); diff --git a/src/main/java/org/sopt/app/interfaces/postgres/NotificationRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/NotificationRepository.java index d7e3df67..4c755036 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/NotificationRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/NotificationRepository.java @@ -12,5 +12,6 @@ public interface NotificationRepository extends JpaRepository findAllByUserId(Long userId, Pageable pageable); + Optional findByIdAndUserId(Long id, Long userId); Optional findByNotificationIdAndUserId(String notificationId, Long userId); } diff --git a/src/main/java/org/sopt/app/presentation/notification/NotificationController.java b/src/main/java/org/sopt/app/presentation/notification/NotificationController.java index 3601b3e5..fb7c98cd 100644 --- a/src/main/java/org/sopt/app/presentation/notification/NotificationController.java +++ b/src/main/java/org/sopt/app/presentation/notification/NotificationController.java @@ -39,7 +39,7 @@ public class NotificationController { @ApiResponse(responseCode = "200", description = "success"), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) - @GetMapping(value = "") + @GetMapping(value = "/all") public ResponseEntity> findNotificationList( @AuthenticationPrincipal User user, @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable @@ -62,7 +62,7 @@ public ResponseEntity> findNotific @ApiResponse(responseCode = "200", description = "success"), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) - @GetMapping(value = "/{notificationId}") + @GetMapping(value = "/detail/{notificationId}") public ResponseEntity findNotificationDetail( @AuthenticationPrincipal User user, @PathVariable("notificationId") String notificationId @@ -70,8 +70,8 @@ public ResponseEntity findNotificationD val result = notificationService.findNotification(user, notificationId); return ResponseEntity.status(HttpStatus.OK).body( NotificationResponse.NotificationDetail.of( - notificationId, - user.getId(), + result.getNotificationId(), + result.getUserId(), result.getTitle(), result.getContent(), result.getDeepLink(), @@ -103,7 +103,7 @@ public ResponseEntity registerNotification( @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @PatchMapping(value = { - "/{notificationId}", "" + "/read/{notificationId}", "/read" }) public ResponseEntity updateNotificationIsRead( @AuthenticationPrincipal User user, @@ -113,4 +113,72 @@ public ResponseEntity updateNotificationIsRead( return ResponseEntity.status(HttpStatus.OK).body(null); } + + + @Operation(summary = "알림 목록 조회 - DEPRECATED") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping(value = "") + @Deprecated + public ResponseEntity> findNotificationListDeprecated( + @AuthenticationPrincipal User user, + @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable + ) { + val result = notificationService.findNotificationList(user, pageable); + return ResponseEntity.status(HttpStatus.OK).body( + result.stream() + .map((notification) -> NotificationResponse.NotificationSimpleDeprecated.of( + notification.getId() + , notification.getUserId() + , notification.getTitle() + , notification.getContent() + , notification.getCategory().name() + , notification.getIsRead() + , notification.getCreatedAt() + )).toList()); + } + @Operation(summary = "알림 상세 조회 - DEPRECATED") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping(value = "/{notificationId}") + @Deprecated + public ResponseEntity findNotificationDetailDeprecated( + @AuthenticationPrincipal User user, + @PathVariable("notificationId") Long notificationId + ) { + val result = notificationService.findNotificationDeprecated(user, notificationId); + return ResponseEntity.status(HttpStatus.OK).body( + NotificationResponse.NotificationDetailDeprecated.of( + result.getId(), + result.getUserId(), + result.getTitle(), + result.getContent(), + result.getDeepLink(), + result.getWebLink(), + result.getCreatedAt(), + result.getUpdatedAt() + ) + ); + } + + @Operation(summary = "알림 읽음 여부 변경 - DEPRECATED") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @PatchMapping(value = { + "/{notificationId}", "" + }) + @Deprecated + public ResponseEntity updateNotificationIsReadDeprecated( + @AuthenticationPrincipal User user, + @PathVariable(name = "notificationId", required = false) Long notificationId + ) { + notificationService.updateNotificationIsReadDeprecated(user, notificationId); + return ResponseEntity.status(HttpStatus.OK).body(null); + } } diff --git a/src/main/java/org/sopt/app/presentation/notification/NotificationResponse.java b/src/main/java/org/sopt/app/presentation/notification/NotificationResponse.java index 6fd2155c..5595d6e2 100644 --- a/src/main/java/org/sopt/app/presentation/notification/NotificationResponse.java +++ b/src/main/java/org/sopt/app/presentation/notification/NotificationResponse.java @@ -104,4 +104,89 @@ public static NotificationConfirmStatus of( ); } } + + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @ToString + @Deprecated + public static class NotificationSimpleDeprecated { + + @Schema(description = "알림 아이디", example = "1") + private Long id; + + @Schema(description = "앱 유저 아이디", example = "1") + private Long userId; + + @Schema(description = "알림 제목", example = "공지다!") + private String title; + + @Schema(description = "알림 내용", example = "공지 내용은 앱팀 최고입니다.") + private String content; + + @Schema(description = "알림 카테고리", example = "NOTICE") + private String category; + + @Schema(description = "알림 읽음 여부", example = "true") + private Boolean isRead; + + @Schema(description = "알림 생성 일시", example = "2023-03-29T18:39:42.106369") + private LocalDateTime createdAt; + + public static NotificationSimpleDeprecated of( + Long notificationId + , Long userId + , String title + , String content + , String category + , Boolean isRead + , LocalDateTime createdAt + ) { + return new NotificationSimpleDeprecated( + notificationId, userId, title, content, category, isRead, createdAt + ); + } + } + + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @ToString + @Deprecated + public static class NotificationDetailDeprecated { + + @Schema(description = "알림 아이디", example = "1") + private Long id; + @Schema(description = "유저 아이디", example = "1") + private Long userId; + @Schema(description = "알림 제목", example = "공지다!") + private String title; + @Schema(description = "알림 내용", example = "공지 내용은 앱팀 최고입니다.") + private String content; + @Schema(description = "알림 첨부 딥링크") + private String deepLink; + @Schema(description = "알림 첨부 웹링크") + private String webLink; + @Schema(description = "알림 생성 일시", example = "2023-03-29T18:39:42.106369") + private LocalDateTime createdAt; + @Schema(description = "알림 수정 일시", example = "2023-03-29T18:39:42.106369") + private LocalDateTime updatedAt; + + public static NotificationDetailDeprecated of( + Long notificationId + , Long userId + , String title + , String content + , String deepLink + , String webLink + , LocalDateTime createdAt + , LocalDateTime updatedAt + ) { + return new NotificationDetailDeprecated( + notificationId, userId, title, content, deepLink, webLink, createdAt, updatedAt + ); + } + } + + }