Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OING-325] feat: 가족구성원 랭킹 API 기능 구현 #246

Merged
merged 11 commits into from
May 6, 2024
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
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) {
Kwon770 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading