Skip to content

Commit

Permalink
fix: 사용자 알림 목록 응답 타입 수정 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom committed Jan 4, 2025
1 parent a77b4a7 commit 15aa053
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.client;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -16,6 +17,7 @@
@RequiredArgsConstructor
@Component
public class AlarmClientManager {

private final AlarmServerProperty alarmServerProperty;

@InternalApiMonitored(name = "status")
Expand All @@ -36,10 +38,10 @@ public NotificationExistServiceResponse getNotificationExist(
}

@InternalApiMonitored(name = "list")
public NotificationPaginationResponse getNotificationPagination(UUID cursorId,
int size, String userFcmToken) {
public NotificationPaginationResponse getNotificationPagination(String userFcmToken,
UUID cursorId, LocalDateTime cursorValue, int size) {
ResponseEntity<NotificationPaginationResponse> result =
RestClient.create(createNotificationsUrl(userFcmToken, cursorId, size))
RestClient.create(createNotificationsUrl(userFcmToken, cursorId, cursorValue, size))
.post()
.retrieve()
.toEntity(NotificationPaginationResponse.class);
Expand All @@ -48,7 +50,7 @@ public NotificationPaginationResponse getNotificationPagination(UUID cursorId,
return result.getBody();
}

private String createNotificationsUrl(String userFcmToken, UUID cursorId, int size) {
private String createNotificationsUrl(String userFcmToken, UUID cursorId, LocalDateTime cursorValue, int size) {
StringBuilder urlBuilder = new StringBuilder(alarmServerProperty.apiURL())
.append("/show-alarm?fcmToken=")
.append(userFcmToken)
Expand All @@ -59,6 +61,10 @@ private String createNotificationsUrl(String userFcmToken, UUID cursorId, int si
urlBuilder.append("&cursorId=").append(cursorId);
}

if (cursorValue != null) {
urlBuilder.append("&cursorValue=").append(cursorValue);
}

return urlBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Max;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.controller.dto.param.SimpleNotificationApiParam;
Expand Down Expand Up @@ -43,20 +44,21 @@ public SuccessResponse<NotificationExistApiResponse> hasUnreadNotifications(
@Operation(summary = "알림 목록")
public SuccessResponse<PaginationApiResponse<SimpleNotificationApiParam>> getNotifications(
@RequestParam(value = "cursorId", required = false) UUID cursorId,
@RequestParam(value = "cursorValue", required = false) LocalDateTime cursorValue,
@RequestParam(value = "size") @Max(value = 30, message = "조회하는 데이터의 최대 개수는 30입니다.")
Integer size,
@AuthenticationPrincipal AuthenticatedInfo info

) {
var response = userAlarmService.findNotifications(info.userId(), cursorId, size);
var response = userAlarmService.findNotifications(info.userId(), cursorId, cursorValue, size);
var data = response.data().stream()
.map(SimpleNotificationApiParam::from)
.toList();

return SuccessResponse.ok(PaginationApiResponse.<SimpleNotificationApiParam>builder()
.hasNext(response.hasNext())
.data(data)
.cursor(response.cursor())
.build());
.hasNext(response.hasNext())
.data(data)
.cursor(response.cursor())
.build());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
Expand Down Expand Up @@ -29,10 +30,11 @@ public NotificationExistServiceResponse getNotificationExist(UUID userId) {
return alarmClientManager.getNotificationExist(userFcmToken);
}

public NotificationServiceResponse findNotifications(UUID userId, UUID cursorId, int size) {
public NotificationServiceResponse findNotifications(UUID userId, UUID cursorId,
LocalDateTime cursorValue, int size) {
String userFcmToken = findUserFcmTokenById(userId);

var response = alarmClientManager.getNotificationPagination(cursorId, size, userFcmToken);
var response = alarmClientManager.getNotificationPagination(userFcmToken, cursorId, cursorValue, size);
if (response != null) {
List<UUID> showIds = response.data().stream()
.map(NotificationInfoResponse::showId)
Expand Down

0 comments on commit 15aa053

Please sign in to comment.