Skip to content

Commit 1b038a5

Browse files
committed
feature(SCRUM-202) : 방문기록 전체 조회 pagiNation 구현
1 parent 9c858eb commit 1b038a5

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

src/main/java/com/team_nebula/nebula/domain/history/api/HistoryController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44

5+
import com.team_nebula.nebula.domain.history.dto.response.GetHistoryListPageResponseDTO;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
57
import org.springframework.data.domain.PageRequest;
68
import org.springframework.data.domain.Pageable;
79
import org.springframework.web.bind.annotation.GetMapping;
@@ -23,6 +25,7 @@
2325

2426
@RestController
2527
@RequiredArgsConstructor
28+
@Tag(name = "[ 방문기록 ]")
2629
@RequestMapping("/api/v1/histories")
2730
public class HistoryController {
2831

@@ -42,7 +45,7 @@ public ApiResponse<?> createHistories(
4245
// 방문기록 전체 조회 API
4346
@Operation(summary = "방문기록 전체 조회", description = "사용자의 모든 방문기록 조회하는 API")
4447
@GetMapping
45-
public ApiResponse<List<GetHistoryListResponseDTO>> getHistories(
48+
public ApiResponse<GetHistoryListPageResponseDTO> getHistories(
4649
@AuthUser Long userId,
4750
@RequestParam(name = "page", defaultValue = "0") int page,
4851
@RequestParam(name = "size", defaultValue = "7") int size) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.team_nebula.nebula.domain.history.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.List;
9+
10+
@Getter
11+
@Builder
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
public class GetHistoryListPageResponseDTO {
15+
private int maxPage;
16+
private boolean hasNext;
17+
private List<GetHistoryListResponseDTO> content;
18+
19+
}

src/main/java/com/team_nebula/nebula/domain/history/service/HistoryQueryService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import java.util.List;
44

5+
import com.team_nebula.nebula.domain.history.dto.response.GetHistoryListPageResponseDTO;
56
import org.springframework.data.domain.Pageable;
67

78
import com.team_nebula.nebula.domain.history.dto.response.GetHistoryListResponseDTO;
89

910
public interface HistoryQueryService {
10-
List<GetHistoryListResponseDTO> getHistories(Long userId, Pageable pageable);
11+
GetHistoryListPageResponseDTO getHistories(Long userId, Pageable pageable);
1112
}

src/main/java/com/team_nebula/nebula/domain/history/service/HistoryQueryServiceImpl.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Set;
55

6+
import com.team_nebula.nebula.domain.history.dto.response.GetHistoryListPageResponseDTO;
67
import org.springframework.data.domain.Page;
78
import org.springframework.data.domain.Pageable;
89
import org.springframework.stereotype.Service;
@@ -28,7 +29,7 @@ public class HistoryQueryServiceImpl implements HistoryQueryService {
2829
private final StarQueryService starQueryService;
2930

3031
@Override
31-
public List<GetHistoryListResponseDTO> getHistories(Long userId, Pageable pageable) {
32+
public GetHistoryListPageResponseDTO getHistories(Long userId, Pageable pageable) {
3233
User user = userQueryService.getUserEntity(userId);
3334
Page<History> historyPage = historyRepository.findAllByUser(user, pageable);
3435
List<History> historyList = historyPage.getContent();
@@ -39,8 +40,24 @@ public List<GetHistoryListResponseDTO> getHistories(Long userId, Pageable pageab
3940

4041
Set<String> starUrls = starQueryService.getStarUrls(urls, userId);
4142

42-
return historyList.stream()
43-
.map(history -> HistoryConverter.convertToHistoryListDto(history, starUrls))
44-
.toList();
43+
List<GetHistoryListResponseDTO> dtoList = historyList.stream()
44+
.map(history -> HistoryConverter.convertToHistoryListDto(history, starUrls))
45+
.toList();
46+
47+
int maxPage;
48+
if (historyPage.getTotalPages() > 0) {
49+
maxPage = historyPage.getTotalPages() - 1;
50+
} else {
51+
maxPage = 0;
52+
}
53+
54+
boolean hasNext = historyPage.hasNext();
55+
56+
57+
return GetHistoryListPageResponseDTO.builder()
58+
.maxPage(maxPage)
59+
.hasNext(hasNext)
60+
.content(dtoList)
61+
.build();
4562
}
4663
}

0 commit comments

Comments
 (0)