Skip to content

Commit

Permalink
[OING-325] feat: 가족구성원 랭킹 API 기능 구현 (#246)
Browse files Browse the repository at this point in the history
* feat: Add getFamilyMembersMonthlySurvivalRanking API in PostController

* feat: Add mvc test code for new API(getFamilyMembersMonthlySurvivalRanking) with nested test class

* feat: Impl getFamilyMemberMonthlyRanking API at MainViewController

* feat: Add mvc test code for new API(getFamilyMemberMonthlyRanking) at MainViewApiTest

* fix: Add stream filter to exclude familyMember who didnt upload post at that month from getFamilyMembersMonthlySurvivalRanking API of PostController and Add test code to validate it from PostApiTest and MainViewApiTest

* fix: Fix failed broken test code

* fix: Fix failed broken test code2

* refactor: Refactor compareTo method of PostRankerDTO for better readability

* refactor: Add blank line at that last of MainViewApiTest

* refactor: Extract duplicated mapping code from getFamilyMemberMonrhlyRanking method of MainViewController

* fix: Fix IndexOutOfBoundsException from getFamilyMemberMonthlyRanking API
  • Loading branch information
Kwon770 authored and Ji-soo708 committed May 9, 2024
1 parent e4d1c0e commit 321ab3e
Show file tree
Hide file tree
Showing 19 changed files with 725 additions and 26 deletions.
42 changes: 37 additions & 5 deletions gateway/src/main/java/com/oing/controller/MainViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class MainViewController implements MainViewApi {
private final PostService postService;
private final MemberService memberService;
private final MemberPickService memberPickService;
private final MemberController memberController;
private final MemberBridge memberBridge;
private final MissionBridge missionBridge;
private final PostController postController;
Expand Down Expand Up @@ -164,13 +165,44 @@ public NighttimePageResponse getNighttimePage(String loginMemberId, String login

@Override
public FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking(String loginMemberId, String loginFamilyId) {
// TODO: API Response Mocking 입니다.
List<PostRankerResponse> ranking = postController.getFamilyMembersMonthlySurvivalRanking(loginFamilyId).results().stream().toList();

FamilyMemberRankerResponse first = null;
if (ranking.size() >= 1) {
first = getFamilyMemberRankerResponse(ranking.get(0), loginFamilyId);
}

FamilyMemberRankerResponse second = null;
if (ranking.size() >= 2) {
second = getFamilyMemberRankerResponse(ranking.get(1), loginFamilyId);
}

FamilyMemberRankerResponse first = new FamilyMemberRankerResponse("https://static01.nyt.com/images/2016/09/28/us/28xp-pepefrog/28xp-pepefrog-superJumbo.jpg", "정신적 지주", 24);
FamilyMemberRankerResponse second = new FamilyMemberRankerResponse("https://static01.nyt.com/images/2016/09/28/us/28xp-pepefrog/28xp-pepefrog-superJumbo.jpg", "권순찬", 23);
FamilyMemberRankerResponse third = null;
LocalDate mostRecentSurvivalPostDate = LocalDate.now().minusDays(1);
if (ranking.size() >= 3) {
third = getFamilyMemberRankerResponse(ranking.get(2), loginFamilyId);
}

return new FamilyMemberMonthlyRankingResponse(4, first, second, third, mostRecentSurvivalPostDate);
LocalDate mostRecentSurvivalPostDate = null;
List<PostResponse> mostRecentPosts = postController.fetchDailyFeeds(1, 1, null, null, "desc", PostType.SURVIVAL, loginMemberId, false).results().stream().toList();
if (!mostRecentPosts.isEmpty()) {
mostRecentSurvivalPostDate = mostRecentPosts.get(0).createdAt().toLocalDate();
}

return new FamilyMemberMonthlyRankingResponse(
ZonedDateTime.now().getMonthValue(),
first,
second,
third,
mostRecentSurvivalPostDate
);
}

private FamilyMemberRankerResponse getFamilyMemberRankerResponse(PostRankerResponse postRankerResponse, String loginFamilyId) {
MemberResponse postRankerMember = memberController.getMember(postRankerResponse.memberId(), loginFamilyId);
return new FamilyMemberRankerResponse(
postRankerMember.imageUrl(),
postRankerMember.name(),
postRankerResponse.postCount()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public record FamilyMemberMonthlyRankingResponse(
@Schema(description = "랭킹 기준 월")
Integer month,

@Schema(description = "(응답모킹됨) 1등 랭커 Dto")
@Schema(description = "1등 랭커 Dto")
FamilyMemberRankerResponse firstRanker,

@Schema(description = "(응답모킹됨) 2등 랭커 Dto")
@Schema(description = "2등 랭커 Dto")
FamilyMemberRankerResponse secondRanker,

@Schema(description = "(응답모킹됨) 3등 랭커 Dto")
@Schema(description = "3등 랭커 Dto")
FamilyMemberRankerResponse thirdRanker,

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

@Schema(description = "가족구성원 랭커 응답")
public record FamilyMemberRankerResponse(

@Schema(description = "랭커의 프로필 사진 Url", example = "https://no5ing.com/profile/1.jpg")
String profileImageUrl,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.oing.domain.Post;
import com.oing.domain.PostType;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.Ops;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down Expand Up @@ -78,15 +79,15 @@ public long countMonthlyPostByFamilyId(int year, int month, String familyId) {
.fetchFirst();
}

private BooleanExpression eqDate(LocalDate date) {
DateTimeTemplate<LocalDate> createdAtDate = Expressions.dateTimeTemplate(LocalDate.class,
"DATE({0})", post.createdAt);

return date == null ? null : createdAtDate.eq(date);
}

private BooleanExpression eqMemberId(String memberId) {
return memberId == null ? null : post.memberId.eq(memberId);
@Override
public long countMonthlyPostByMemberId(int year, int month, String memberId) {
return queryFactory
.select(post.count())
.from(post)
.where(post.memberId.eq(memberId),
post.createdAt.year().eq(year),
post.createdAt.month().eq(month))
.fetchFirst();
}

@Override
Expand Down Expand Up @@ -163,11 +164,32 @@ public int countTodaySurvivalPostsByFamilyId(String familyId) {
return count.intValue();
}

private BooleanExpression isActiveMember() {
return member.deletedAt.isNull();
private BooleanExpression eqDate(LocalDate date) {
DateTimeTemplate<LocalDate> createdAtDate = Expressions.dateTimeTemplate(LocalDate.class,
"DATE({0})", post.createdAt);

return date == null ? null : createdAtDate.eq(date);
}

private BooleanBuilder eqMonth(LocalDate date) {
return date == null ? null : new BooleanBuilder()
.and(post.createdAt.year().eq(date.getYear()))
.and(post.createdAt.month().eq(date.getMonthValue()));
}

private DateTimeTemplate<LocalDate> dateExpr(DateTimePath<LocalDateTime> localDateTime) {
return Expressions.dateTimeTemplate(LocalDate.class, "DATE({0})", localDateTime);
}

private BooleanExpression eqMemberId(String memberId) {
return memberId == null ? null : post.memberId.eq(memberId);
}

private BooleanExpression isActiveMember() {
return member.deletedAt.isNull();
}

private BooleanExpression eqPostType(PostType postType) {
return postType == null ? null : post.type.eq(postType);
}
}
Loading

0 comments on commit 321ab3e

Please sign in to comment.