Skip to content

Commit 6c50513

Browse files
committed
CLAP-145 Fix: 반환값을 Page가 Slice로 설정
1 parent 0f756ae commit 6c50513

File tree

9 files changed

+44
-84
lines changed

9 files changed

+44
-84
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package clap.server.adapter.inbound.web.dto.common;
2+
3+
4+
import java.util.List;
5+
6+
public record SliceResponse<T> (
7+
List<T> content,
8+
int currentPage,
9+
int size,
10+
boolean isFirst,
11+
boolean isLast
12+
) {
13+
}

src/main/java/clap/server/adapter/inbound/web/notification/FindNotificationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package clap.server.adapter.inbound.web.notification;
22

33
import clap.server.adapter.inbound.security.SecurityUserDetails;
4+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
45
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
56
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
67
import clap.server.common.annotation.architecture.WebAdapter;
@@ -9,7 +10,6 @@
910
import io.swagger.v3.oas.annotations.Parameters;
1011
import io.swagger.v3.oas.annotations.tags.Tag;
1112
import lombok.RequiredArgsConstructor;
12-
import org.springframework.data.domain.Page;
1313
import org.springframework.data.domain.PageRequest;
1414
import org.springframework.data.domain.Pageable;
1515
import org.springframework.http.ResponseEntity;
@@ -34,7 +34,7 @@ public class FindNotificationController {
3434
@Parameter(name = "size", description = "조회할 목록 페이지 당 개수", example = "5", required = false)
3535
})
3636
@GetMapping
37-
public ResponseEntity<Page<FindNotificationListResponse>> findNotificationList(
37+
public ResponseEntity<SliceResponse<FindNotificationListResponse>> findNotificationList(
3838
@AuthenticationPrincipal SecurityUserDetails securityUserDetails,
3939
@RequestParam(defaultValue = "0") int page,
4040
@RequestParam(defaultValue = "5") int size) {

src/main/java/clap/server/adapter/outbound/persistense/NotificationPersistenceAdapter.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package clap.server.adapter.outbound.persistense;
22

3+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
34
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
45
import clap.server.adapter.outbound.persistense.mapper.NotificationPersistenceMapper;
56
import clap.server.adapter.outbound.persistense.repository.notification.NotificationRepository;
@@ -9,8 +10,8 @@
910
import clap.server.common.annotation.architecture.PersistenceAdapter;
1011
import clap.server.domain.model.notification.Notification;
1112
import lombok.RequiredArgsConstructor;
12-
import org.springframework.data.domain.Page;
1313
import org.springframework.data.domain.Pageable;
14+
import org.springframework.data.domain.Slice;
1415

1516
import java.util.List;
1617
import java.util.Optional;
@@ -31,10 +32,14 @@ public Optional<Notification> findById(Long notificationId) {
3132
}
3233

3334
@Override
34-
public Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
35-
Page<Notification> notificationList = notificationRepository.findAllByReceiver_MemberId(receiverId, pageable)
35+
public SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
36+
Slice<Notification> notificationList = notificationRepository
37+
.findAllByReceiver_MemberIdOrderByCreatedAtDesc(receiverId, pageable)
3638
.map(notificationPersistenceMapper::toDomain);
37-
return notificationList.map(NotificationMapper::toFindNoticeListResponse);
39+
40+
return NotificationMapper.toSliceOfFindNoticeListResponse(
41+
notificationList.map(NotificationMapper::toFindNoticeListResponse)
42+
);
3843
}
3944

4045
@Override
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package clap.server.adapter.outbound.persistense.repository.notification;
22

33
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
4-
import org.springframework.data.domain.Page;
54
import org.springframework.data.domain.Pageable;
5+
import org.springframework.data.domain.Slice;
66
import org.springframework.data.jpa.repository.JpaRepository;
77
import org.springframework.stereotype.Repository;
88

@@ -12,7 +12,7 @@
1212
@Repository
1313
public interface NotificationRepository extends JpaRepository<NotificationEntity, Long> {
1414

15-
Page<NotificationEntity> findAllByReceiver_MemberId(Long receiverId, Pageable pageable);
15+
Slice<NotificationEntity> findAllByReceiver_MemberIdOrderByCreatedAtDesc(Long receiverId, Pageable pageable);
1616

1717
List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);
1818
}

src/main/java/clap/server/application/mapper/NotificationMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package clap.server.application.mapper;
22

3+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
34
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
45
import clap.server.domain.model.notification.Notification;
6+
import org.springframework.data.domain.Slice;
57

68
public class NotificationMapper {
79
private NotificationMapper() {throw new IllegalArgumentException();}
@@ -17,4 +19,14 @@ public static FindNotificationListResponse toFindNoticeListResponse(Notification
1719
notification.getCreatedAt()
1820
);
1921
}
22+
23+
public static SliceResponse<FindNotificationListResponse> toSliceOfFindNoticeListResponse(Slice<FindNotificationListResponse> slice) {
24+
return new SliceResponse<>(
25+
slice.getContent(),
26+
slice.getNumber(),
27+
slice.getSize(),
28+
slice.isFirst(),
29+
slice.isLast()
30+
);
31+
}
2032
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package clap.server.application.port.inbound.notification;
22

3+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
34
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
4-
import org.springframework.data.domain.Page;
55
import org.springframework.data.domain.Pageable;
66

77
public interface FindNotificationListUsecase {
8-
Page<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable);
8+
SliceResponse<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable);
99
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package clap.server.application.port.outbound.notification;
22

3+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
34
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
4-
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
55
import clap.server.domain.model.notification.Notification;
6-
import org.springframework.data.domain.Page;
76
import org.springframework.data.domain.Pageable;
8-
97
import java.util.List;
108
import java.util.Optional;
119

@@ -14,7 +12,7 @@ public interface LoadNotificationPort {
1412

1513
Optional<Notification> findById(Long notificationId);
1614

17-
Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
15+
SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
1816

1917
List<Notification> findNotificationsByMemberId(Long memberId);
2018
}

src/main/java/clap/server/application/service/notification/FindNotificationListService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package clap.server.application.service.notification;
22

3+
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
34
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
45
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
56
import clap.server.application.port.outbound.notification.LoadNotificationPort;
67
import clap.server.common.annotation.architecture.ApplicationService;
78
import lombok.RequiredArgsConstructor;
8-
import org.springframework.data.domain.Page;
99
import org.springframework.data.domain.Pageable;
1010
import org.springframework.transaction.annotation.Transactional;
1111

@@ -18,7 +18,7 @@ public class FindNotificationListService implements FindNotificationListUsecase
1818

1919

2020
@Override
21-
public Page<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable) {
21+
public SliceResponse<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable) {
2222
return loadNotificationPort.findAllByReceiverId(receiverId, pageable);
2323
}
2424
}

src/test/java/clap/server/notification/NotificationServiceTest.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)