Skip to content

Commit

Permalink
refactor: 다른 랭킹도 추가할 수 있도록 Rankable 마커 인터페이스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc committed Feb 17, 2024
1 parent 3ac179e commit c7066ca
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public record RankResponses(List<SupporterResponse> data) {
public record RankResponses<T extends Rankable>(List<T> data) {

public static RankResponses from(final List<Supporter> supporters) {
public static RankResponses<SupporterRank> from(final List<Supporter> supporters) {
final AtomicInteger rank = new AtomicInteger(1);
final List<SupporterResponse> responses = supporters.stream()
.map(supporter -> new SupporterResponse(
final List<SupporterRank> responses = supporters.stream()
.map(supporter -> new SupporterRank(
rank.getAndIncrement(),
supporter.getMember().getMemberName().getValue(),
supporter.getId(),
Expand All @@ -23,10 +23,10 @@ public static RankResponses from(final List<Supporter> supporters) {
.toList()))
.toList();

return new RankResponses(responses);
return new RankResponses<>(responses);
}

public record SupporterResponse(
public record SupporterRank(
int rank,
String name,
long supporterId,
Expand All @@ -35,7 +35,7 @@ public record SupporterResponse(
String githubUrl,
String company,
List<String> technicalTags
) {
) implements Rankable {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package touch.baton.domain.member.query.controller.response;

public interface Rankable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RankQueryService {

private final RankQuerydslRepository rankQueryDslRepository;

public RankResponses readMostReviewSupporter(final int maxCount) {
public RankResponses<RankResponses.SupporterRank> readMostReviewSupporter(final int maxCount) {
return RankResponses.from(rankQueryDslRepository.findMostReviewSupporterByCount(maxCount));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package touch.baton.assure.member.support.query;

import io.restassured.common.mapper.TypeRef;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import touch.baton.assure.common.AssuredSupport;
Expand Down Expand Up @@ -46,18 +47,18 @@ public RankQueryResponseBuilder(final ExtractableResponse<Response> response) {
this.response = response;
}

public void 서포터_리뷰_랭킹_조회_성공을_검증한다(final List<RankResponses.SupporterResponse> 랭킹_응답) {
final RankResponses actual = this.response.as(RankResponses.class);
public void 서포터_리뷰_랭킹_조회_성공을_검증한다(final List<RankResponses.SupporterRank> 랭킹_응답) {
final RankResponses<RankResponses.SupporterRank> actual = this.response.as(new TypeRef<>(){});

assertSoftly(softly -> {
softly.assertThat(actual.data()).hasSize(랭킹_응답.size());
softly.assertThat(actual.data()).isEqualTo(랭킹_응답);
});
}

public static RankResponses.SupporterResponse 서포터_리뷰_랭킹_응답(final int 순위, final Supporter 서포터, final int 리뷰수) {
public static RankResponses.SupporterRank 서포터_리뷰_랭킹_응답(final int 순위, final Supporter 서포터, final int 리뷰수) {
final Member member = 서포터.getMember();
return new RankResponses.SupporterResponse(순위,
return new RankResponses.SupporterRank(순위,
member.getMemberName().getValue(),
서포터.getId(),
리뷰수,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class RankReadApiTest extends RestdocsConfig {
@Test
void readMostReviewSupporter() throws Exception {
// given
final List<RankResponses.SupporterResponse> response = List.of(
new RankResponses.SupporterResponse(1, "ethan", 1L, 10, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterResponse(2, "hyena", 2L, 9, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterResponse(3, "ditoo", 3L, 8, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterResponse(4, "aiden", 4L, 7, "imageUrl", "githubUrl", "우아한테크코스", List.of("javascript", "react")),
new RankResponses.SupporterResponse(5, "ditoo", 5L, 6, "imageUrl", "githubUrl", "우아한테크코스", List.of("javascript", "react"))
final List<RankResponses.SupporterRank> response = List.of(
new RankResponses.SupporterRank(1, "ethan", 1L, 10, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterRank(2, "hyena", 2L, 9, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterRank(3, "ditoo", 3L, 8, "imageUrl", "githubUrl", "우아한테크코스", List.of("java", "spring")),
new RankResponses.SupporterRank(4, "aiden", 4L, 7, "imageUrl", "githubUrl", "우아한테크코스", List.of("javascript", "react")),
new RankResponses.SupporterRank(5, "ditoo", 5L, 6, "imageUrl", "githubUrl", "우아한테크코스", List.of("javascript", "react"))
);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void readMostReviewSupporter() {

// when
final int maxCount = 5;
final RankResponses actual = rankQueryService.readMostReviewSupporter(maxCount);
final RankResponses<RankResponses.SupporterRank> actual = rankQueryService.readMostReviewSupporter(maxCount);

// then
assertAll(
Expand All @@ -73,7 +73,7 @@ void readMostReviewSupporter() {
);
}

private static void assertResponse(final RankResponses.SupporterResponse response, final int rank, final String memberName, final int reviewCount) {
private static void assertResponse(final RankResponses.SupporterRank response, final int rank, final String memberName, final int reviewCount) {
assertAll(
() -> assertThat(response.rank()).isEqualTo(rank),
() -> assertThat(response.name()).isEqualTo(memberName),
Expand Down

0 comments on commit c7066ca

Please sign in to comment.