Skip to content

Commit b3b3270

Browse files
committed
feat: 랭킹 조회 API 컨트롤러 구현
- GET /api/v1/rankings?date=&page=&size= - page 파라미터 1-based (API) → 0-based (내부) 변환
1 parent bac5304 commit b3b3270

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.loopers.interfaces.api.ranking;
2+
3+
import com.loopers.application.ranking.RankingFacade;
4+
import com.loopers.application.ranking.RankingInfo.RankingPageInfo;
5+
import com.loopers.interfaces.api.ApiResponse;
6+
import com.loopers.interfaces.api.ranking.RankingV1Dto.RankingPageResponse;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.web.bind.annotation.*;
9+
10+
@RequiredArgsConstructor
11+
@RestController
12+
@RequestMapping("/api/v1")
13+
public class RankingV1Controller {
14+
15+
private final RankingFacade rankingFacade;
16+
17+
/**
18+
* 랭킹 페이지 조회
19+
* GET /api/v1/rankings?date=yyyyMMdd&size=20&page=1
20+
*
21+
* @param page 페이지 번호 (1-based, 기본값 1)
22+
*/
23+
@GetMapping("/rankings")
24+
public ApiResponse<RankingPageResponse> getRankings(
25+
@RequestParam(value = "date", required = false) String date,
26+
@RequestParam(value = "page", defaultValue = "1") int page,
27+
@RequestParam(value = "size", defaultValue = "20") int size
28+
) {
29+
// API는 1-based, 내부는 0-based로 변환
30+
int zeroBasedPage = Math.max(0, page - 1);
31+
RankingPageInfo info = rankingFacade.getRankings(date, zeroBasedPage, size);
32+
RankingPageResponse response = RankingPageResponse.from(info);
33+
return ApiResponse.success(response);
34+
}
35+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.loopers.interfaces.api.ranking;
2+
3+
import com.loopers.application.ranking.RankingInfo.RankingItemInfo;
4+
import com.loopers.application.ranking.RankingInfo.RankingPageInfo;
5+
6+
import java.math.BigDecimal;
7+
import java.util.List;
8+
9+
public class RankingV1Dto {
10+
11+
public record RankingPageResponse(
12+
List<RankingItemResponse> rankings,
13+
String date,
14+
int page, // 1-based page number for API response
15+
int size,
16+
long totalCount,
17+
int totalPages,
18+
boolean hasNext
19+
) {
20+
public static RankingPageResponse from(RankingPageInfo info) {
21+
List<RankingItemResponse> rankings = info.rankings().stream()
22+
.map(RankingItemResponse::from)
23+
.toList();
24+
return new RankingPageResponse(
25+
rankings,
26+
info.date(),
27+
info.page() + 1, // 0-based → 1-based 변환
28+
info.size(),
29+
info.totalCount(),
30+
info.totalPages(),
31+
info.hasNext()
32+
);
33+
}
34+
}
35+
36+
public record RankingItemResponse(
37+
int rank,
38+
Long productId,
39+
String productName,
40+
String brandName,
41+
BigDecimal price,
42+
int likeCount,
43+
Double score
44+
) {
45+
public static RankingItemResponse from(RankingItemInfo info) {
46+
return new RankingItemResponse(
47+
info.rank(),
48+
info.productId(),
49+
info.productName(),
50+
info.brandName(),
51+
info.price().getAmount(),
52+
info.likeCount(),
53+
info.score()
54+
);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)