Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ public ResponseEntity<ConcertDetailResponse> getConcertDetail(@PathVariable Long
return ResponseEntity.ok(response);
}

@GetMapping("/popular")
public ResponseEntity<List<ConcertSimpleResponse>> getPopularConcerts() {
return ResponseEntity.ok(concertService.getPopularConcerts());
@GetMapping("/popular/daily")
public ResponseEntity<List<ConcertSimpleResponse>> getDailyPopularConcerts() {
return ResponseEntity.ok(concertService.getDailyPopularConcerts());
}

@GetMapping("/popular/weekly")
public ResponseEntity<List<ConcertSimpleResponse>> getWeeklyPopularConcerts() {
return ResponseEntity.ok(concertService.getWeeklyPopularConcerts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public List<Long> getTopConcertIds(int limit) {
.toList();
}

public List<Long> getTopConcertIds(String key, int limit) {
Set<Object> ids = redisTemplate.opsForZSet()
.reverseRange(key, 0, limit - 1);
return ids.stream().map(id -> Long.valueOf(id.toString())).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public interface ConcertService {

ConcertDetailResponse getConcertDetail(Long concertId);

List<ConcertSimpleResponse> getPopularConcerts();
List<ConcertSimpleResponse> getDailyPopularConcerts();

List<ConcertSimpleResponse> getWeeklyPopularConcerts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,26 @@ public ConcertDetailResponse getConcertDetail(Long concertId) {
}

@Override
public List<ConcertSimpleResponse> getPopularConcerts() {
List<Long> topIds = concertCacheService.getTopConcertIds(7);
List<Concert> concerts = concertRepository.findByIdIn(topIds);
public List<ConcertSimpleResponse> getDailyPopularConcerts() {
List<Long> ids = concertCacheService.getTopConcertIds("ranking:daily", 7);
return mapConcertsByIdOrder(ids);
}

@Override
public List<ConcertSimpleResponse> getWeeklyPopularConcerts() {
List<Long> ids = concertCacheService.getTopConcertIds("ranking:weekly", 7);
return mapConcertsByIdOrder(ids);
}

private List<ConcertSimpleResponse> mapConcertsByIdOrder(List<Long> ids) {
List<Concert> concerts = concertRepository.findByIdIn(ids);
Map<Long, Concert> concertMap = concerts.stream()
.collect(Collectors.toMap(Concert::getId, c -> c));

return topIds.stream()
return ids.stream()
.map(concertMap::get)
.filter(Objects::nonNull)
.map(c -> new ConcertSimpleResponse(
c.getId(),
c.getTitle(),
c.getVenue().getName(),
c.getCategory().name()
c.getId(), c.getTitle(), c.getVenue().getName(), c.getCategory().name()
))
.toList();
}
Expand Down
Loading