Skip to content

Commit b68e661

Browse files
committed
refactor: LLM 지출분석 결과 페이징 적용
1 parent 2262181 commit b68e661

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/main/java/store/lastdance/controller/expense/ExpenseController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.http.MediaType;
1313
import org.springframework.http.ResponseEntity;
1414
import org.springframework.security.core.annotation.AuthenticationPrincipal;
15-
import org.springframework.security.core.parameters.P;
1615
import org.springframework.web.bind.annotation.*;
1716
import org.springframework.web.multipart.MultipartFile;
1817
import store.lastdance.aspect.RateLimit;
@@ -257,12 +256,18 @@ public ResponseEntity<ApiResponse<String>> saveAnalysisResult(
257256
}
258257

259258
@GetMapping("/analyze/history")
260-
@Operation(summary = "LLM 지출 분석 내역 조회", description = "사용자의 전체 지출 분석 내역을 최신순으로 조회")
261-
public ResponseEntity<ApiResponse<List<ExpenseAnalysisHistoryDTO>>> getAnalysisHistoryList(
262-
@Parameter(hidden = true) @AuthenticationPrincipal CustomOAuth2User oAuth2User
259+
@Operation(summary = "LLM 지출 분석 내역 조회", description = "사용자의 전체 지출 분석 내역을 최신순으로 조회 (페이징 포함)")
260+
public ResponseEntity<ApiResponse<PageWithSummaryResponse<ExpenseAnalysisHistoryDTO>>> getAnalysisHistoryList(
261+
@Parameter(hidden = true) @AuthenticationPrincipal CustomOAuth2User oAuth2User,
262+
@RequestParam(defaultValue = "0") int page,
263+
@RequestParam(defaultValue = "10") int size,
264+
@RequestParam(defaultValue = "createdAt") String sortBy,
265+
@RequestParam(defaultValue = "DESC") String sortDirection
263266
){
264267
UUID userId = oAuth2User.getUserId();
265-
List<ExpenseAnalysisHistoryDTO> response = expenseService.getExpenseAnalysisHistory(userId);
268+
Sort sort = Sort.by(Sort.Direction.fromString(sortDirection), sortBy);
269+
Pageable pageable = PageRequest.of(page, size, sort);
270+
PageWithSummaryResponse<ExpenseAnalysisHistoryDTO> response = expenseService.getExpenseAnalysisHistory(userId,pageable);
266271

267272
return ResponseEntity.ok(ApiResponse.success(response));
268273
}

src/main/java/store/lastdance/repository/expense/ExpenseAnalysisHistoryRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package store.lastdance.repository.expense;
22

3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
35
import org.springframework.data.jpa.repository.JpaRepository;
46
import store.lastdance.domain.expense.ExpenseAnalysisHistory;
57
import store.lastdance.domain.user.User;
@@ -11,4 +13,6 @@ public interface ExpenseAnalysisHistoryRepository extends JpaRepository<ExpenseA
1113

1214
// 특정 사용자의 모든 분석 내역을 최신순으로 조회
1315
List<ExpenseAnalysisHistory> findByUserOrderByCreatedAtDesc(User user);
16+
17+
Page<ExpenseAnalysisHistory> findByUser(User user, Pageable pageable);
1418
}

src/main/java/store/lastdance/service/expense/ExpenseService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PageWithSummaryResponse<CombinedExpenseResponseDTO> getCombinedExpenses(
5656
// LLM 지출 분석 응답
5757
AnalyzeExpenseResponseDTO analyzeExpenses(UUID userId, AnalyzeExpenseRequestDTO requestDTO);
5858
// LLM 지출 분석 내역 조회
59-
List<ExpenseAnalysisHistoryDTO> getExpenseAnalysisHistory(UUID userId);
59+
PageWithSummaryResponse<ExpenseAnalysisHistoryDTO> getExpenseAnalysisHistory(UUID userId, Pageable pageable);
6060
// LLM 지출 분석 내역 저장
6161
void saveExpenseAnalysisHistory(UUID userId, AnalyzeExpenseRequestDTO requestDTO,AnalyzeExpenseResponseDTO analysisResponseDTO);
6262
}

src/main/java/store/lastdance/service/expense/ExpenseServiceImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,14 +1106,15 @@ public AnalyzeExpenseResponseDTO analyzeExpenses(UUID userId, AnalyzeExpenseRequ
11061106
* LLM 지출 분석 기록 조회
11071107
*/
11081108
@Override
1109-
public List<ExpenseAnalysisHistoryDTO> getExpenseAnalysisHistory(UUID userId) {
1109+
public PageWithSummaryResponse<ExpenseAnalysisHistoryDTO> getExpenseAnalysisHistory(UUID userId, Pageable pageable) {
11101110

11111111
User user = userRepository.findById(userId).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
1112-
List<ExpenseAnalysisHistory> historyList = expenseAnalysisHistoryRepository.findByUserOrderByCreatedAtDesc(user);
11131112

1114-
return historyList.stream()
1115-
.map(ExpenseAnalysisHistoryDTO::from)
1116-
.collect(Collectors.toList());
1113+
Page<ExpenseAnalysisHistory> historyPage = expenseAnalysisHistoryRepository.findByUser(user,pageable);
1114+
1115+
Page<ExpenseAnalysisHistoryDTO> historyDTOPage = historyPage.map(ExpenseAnalysisHistoryDTO::from);
1116+
1117+
return PageWithSummaryResponse.of(historyDTOPage, ExpenseSummary.empty());
11171118

11181119
}
11191120

0 commit comments

Comments
 (0)