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-317] refactor: 뷰 기반 API에 대한 교통정리 1 #238

Merged
merged 4 commits into from
Apr 21, 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
23 changes: 0 additions & 23 deletions gateway/src/main/java/com/oing/controller/HomeController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import com.oing.domain.*;
import com.oing.dto.response.*;
import com.oing.restapi.ViewBasedApi;
import com.oing.service.MemberBridge;
import com.oing.service.MemberPickService;
import com.oing.service.MemberService;
import com.oing.service.PostService;
import com.oing.restapi.MainViewApi;
import com.oing.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

/**
Expand All @@ -23,19 +21,24 @@
*/
@Controller
@RequiredArgsConstructor
public class ViewBasedController implements ViewBasedApi {
public class MainViewController implements MainViewApi {

private final PostService postService;
private final MemberService memberService;
private final MemberPickService memberPickService;
private final MemberBridge memberBridge;
private final MissionBridge missionBridge;

private static final int PAGE_FETCH_SIZE = 1000;

@Override
public MainPageResponse getMainPage(
public DaytimePageResponse getDaytimePage(
boolean isMissionUnlocked,
boolean isMeUploadedToday,
String loginMemberId
) {
String familyId = memberBridge.getFamilyIdByMemberId(loginMemberId);
LocalDate today = LocalDate.now();
LocalDate today = ZonedDateTime.now().toLocalDate();
Map<String, FamilyMemberProfileResponse> memberMap = new HashMap<>();
Page<FamilyMemberProfileResponse> members = memberService.getFamilyMembersProfilesByFamilyId(familyId, 1, PAGE_FETCH_SIZE);
members.forEach(member -> memberMap.put(member.memberId(), member));
Expand All @@ -62,8 +65,11 @@ public MainPageResponse getMainPage(
memberPickService.getPickedMembers(familyId, loginMemberId)
.forEach(pick -> pickedSet.add(pick.getToMemberId()));

String todayMissionId = missionBridge.getTodayMissionId();
String dailyMissionContent = missionBridge.getContentByMissionId(todayMissionId);

return new MainPageResponse(

return new DaytimePageResponse(
members.stream().sorted(comparator).map((member) -> new MainPageTopBarResponse(
member.memberId(),
member.imageUrl(),
Expand All @@ -74,10 +80,33 @@ public MainPageResponse getMainPage(
&& member.dayOfBirth().getDayOfMonth() == today.getDayOfMonth(),
!pickedSet.contains(member.memberId())
&& !member.memberId().equals(loginMemberId)
&& !postUploaderRankMap.containsKey(member.memberId())
&& !postUploaderRankMap.containsKey(member.memberId())
)).toList(),
true,
postUploaderRankMap.containsKey(loginMemberId),

memberPickService.getPickMembers(familyId, loginMemberId).stream().map(pickMember -> {
FamilyMemberProfileResponse member = memberMap.get(pickMember.getFromMemberId());
if (member == null) {
return new MainPagePickerResponse(
pickMember.getFromMemberId(),
"UNKNOWN",
"UNKNOWN"
);
}
return new MainPagePickerResponse(
member.memberId(),
member.imageUrl(),
member.name()
);
}).toList(),

2,

isMissionUnlocked,

isMeUploadedToday,

dailyMissionContent,

survivalPosts.stream().map(post -> {
FamilyMemberProfileResponse member = memberMap.get(post.getMemberId());
return new MainPageFeedResponse(
Expand All @@ -87,6 +116,7 @@ public MainPageResponse getMainPage(
post.getCreatedAt().atZone(ZoneId.systemDefault())
);
}).toList(),

missionPosts.stream().map(post -> {
FamilyMemberProfileResponse member = memberMap.get(post.getMemberId());
return new MainPageFeedResponse(
Expand All @@ -95,23 +125,43 @@ public MainPageResponse getMainPage(
member != null ? member.name() : "UNKNOWN",
post.getCreatedAt().atZone(ZoneId.systemDefault())
);
}).toList(),
memberPickService.getPickMembers(familyId, loginMemberId).stream().map(pickMember -> {
FamilyMemberProfileResponse member = memberMap.get(pickMember.getFromMemberId());
if(member == null) {
return new MainPagePickerResponse(
pickMember.getFromMemberId(),
"UNKNOWN",
"UNKNOWN"
);
}
return new MainPagePickerResponse(
member.memberId(),
member.imageUrl(),
member.name()
);
}).toList()
);
}


@Override
public NighttimePageResponse getNighttimePage(String loginMemberId, String loginFamilyId) {
Page<FamilyMemberProfileResponse> members = memberService.getFamilyMembersProfilesByFamilyId(loginFamilyId, 1, PAGE_FETCH_SIZE);
LocalDate today = ZonedDateTime.now().toLocalDate();
List<MainPageTopBarResponse> mainPageTopBarResponses = members.stream().map((member) -> new MainPageTopBarResponse(
member.memberId(),
member.imageUrl(),
String.valueOf(member.name().charAt(0)),
member.name(),
1,
member.dayOfBirth().getMonth() == today.getMonth()
&& member.dayOfBirth().getDayOfMonth() == today.getDayOfMonth(),
false
)).toList();

FamilyMemberMonthlyRankingResponse familyMemberMonthlyRanking = getFamilyMemberMonthlyRanking(loginMemberId, loginFamilyId);

return new NighttimePageResponse(
mainPageTopBarResponses,
familyMemberMonthlyRanking
);
}


@Override
public FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking(String loginMemberId, String loginFamilyId) {
// TODO: API Response Mocking 입니다.

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;

return new FamilyMemberMonthlyRankingResponse(4, first, second, third);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@

import java.util.List;

@Schema(description = "메인 페이지")
public record MainPageResponse(
@Schema(description = "주간 메인 페이지")
public record DaytimePageResponse(
@Schema(description = "상단 바 요소")
List<MainPageTopBarResponse> topBarElements,

@Schema(description = "날 찌른 목록")
List<MainPagePickerResponse> pickers,

@Schema(description = "미션 해금까지 남은 업로드 횟수 (언제나 2로 모킹됨)", example = "3")
Integer leftUploadCountUntilMissionUnlock,

@Schema(description = "미션 해금 여부", example = "true")
boolean isMissionUnlocked,

@Schema(description = "오늘 나 업로드 여부", example = "true")
boolean isMeUploadedToday,

@Schema(description = "오늘의 미션 내용 (모킹됨)", example = "오늘의 기분을 나타내는 사진 찍기.")
String dailyMissionContent,

@Schema(description = "생존 피드 목록")
List<MainPageFeedResponse> survivalFeeds,

@Schema(description = "미션 피드 목록")
List<MainPageFeedResponse> missionFeeds,

@Schema(description = "날 찌른 목록")
List<MainPagePickerResponse> pickers
List<MainPageFeedResponse> missionFeeds
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public record MainPageTopBarResponse(
@Schema(description = "닉네임", example = "엄마")
String displayName,

@Schema(description = "순위 표기", example = "1")
@Schema(description = "순위 표기 (1부터 시작)" +
"\n- 야간의 경우 모두 1입니다."
, example = "1")
Integer displayRank,

@Schema(description = "생일 마크 표시 여부", example = "true")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.oing.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

@Schema(description = "야간 메인 페이지")
public record NighttimePageResponse(
@Schema(description = "상단 바 요소")
List<MainPageTopBarResponse> topBarElements,

@Schema(description = "금월의 가족 구성원 월간 랭킹")
FamilyMemberMonthlyRankingResponse familyMemberMonthlyRanking
) {
}
29 changes: 0 additions & 29 deletions gateway/src/main/java/com/oing/restapi/HomeApi.java

This file was deleted.

69 changes: 69 additions & 0 deletions gateway/src/main/java/com/oing/restapi/MainViewApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.oing.restapi;

import com.oing.dto.response.DaytimePageResponse;
import com.oing.dto.response.FamilyMemberMonthlyRankingResponse;
import com.oing.dto.response.NighttimePageResponse;
import com.oing.util.security.LoginFamilyId;
import com.oing.util.security.LoginMemberId;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* no5ing-server
* User: CChuYong
* Date: 4/16/24
* Time: 4:01 PM
*/
@Tag(name = "메인페이지 뷰 기반 API", description = "프론트의 메인페이지 기반으로 작성된 View API입니다.")
@RestController
@RequestMapping("/v1/view/main")
public interface MainViewApi {

@Operation(summary = "주간의 메인 페이지 조회")
@GetMapping("/daytime-page")
DaytimePageResponse getDaytimePage(

@RequestParam(required = false, defaultValue = "true")
@Parameter(description = "(디버그용) 미션 해금 여부 조작 필드", example = "true")
boolean isMissionUnlocked,

@RequestParam(required = false, defaultValue = "true")
@Parameter(description = "(디버그용) 오늘 나 업로드 여부 조작 필드", example = "true")
boolean isMeUploadedToday,

@Parameter(hidden = true)
@LoginMemberId
String loginMemberId
);


@Operation(summary = "야간의 메인 페이지 조회")
@GetMapping("/nighttime-page")
NighttimePageResponse getNighttimePage(
@Parameter(hidden = true)
@LoginMemberId
String loginMemberId,

@Parameter(hidden = true)
@LoginFamilyId
String loginFamilyId
);


@Operation(summary = "금월의 가족 구성원 월간 랭킹 조회", description = "이번 달에 해당하는 가족 구성원 월간 랭킹을 조회합니다.")
@GetMapping("/family-ranking")
FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking(
@Parameter(hidden = true)
@LoginMemberId
String loginMemberId,

@Parameter(hidden = true)
@LoginFamilyId
String loginFamilyId
);
}
Loading
Loading