Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX : 이전 버전 알림 API 재생성 및 Deprecated 처리 #149

Merged
merged 2 commits into from
Nov 19, 2023
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
Expand Up @@ -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<Notification> findNotificationList(User user, Pageable pageable) {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface NotificationRepository extends JpaRepository<Notification, Long

List<Notification> findAllByUserId(Long userId, Pageable pageable);

Optional<Notification> findByIdAndUserId(Long id, Long userId);
Optional<Notification> findByNotificationIdAndUserId(String notificationId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<NotificationResponse.NotificationSimple>> findNotificationList(
@AuthenticationPrincipal User user,
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
Expand All @@ -62,16 +62,16 @@ public ResponseEntity<List<NotificationResponse.NotificationSimple>> findNotific
@ApiResponse(responseCode = "200", description = "success"),
@ApiResponse(responseCode = "500", description = "server error", content = @Content)
})
@GetMapping(value = "/{notificationId}")
@GetMapping(value = "/detail/{notificationId}")
public ResponseEntity<NotificationResponse.NotificationDetail> findNotificationDetail(
@AuthenticationPrincipal User user,
@PathVariable("notificationId") String notificationId
) {
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(),
Expand Down Expand Up @@ -103,7 +103,7 @@ public ResponseEntity registerNotification(
@ApiResponse(responseCode = "500", description = "server error", content = @Content)
})
@PatchMapping(value = {
"/{notificationId}", ""
"/read/{notificationId}", "/read"
})
public ResponseEntity<NotificationDetail> updateNotificationIsRead(
@AuthenticationPrincipal User user,
Expand All @@ -113,4 +113,72 @@ public ResponseEntity<NotificationDetail> 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<List<NotificationResponse.NotificationSimpleDeprecated>> 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<NotificationResponse.NotificationDetailDeprecated> 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<NotificationDetail> updateNotificationIsReadDeprecated(
@AuthenticationPrincipal User user,
@PathVariable(name = "notificationId", required = false) Long notificationId
) {
notificationService.updateNotificationIsReadDeprecated(user, notificationId);
return ResponseEntity.status(HttpStatus.OK).body(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}


}
Loading