From d37bedd95f15d696300e9c9e2bb11339fa910fae Mon Sep 17 00:00:00 2001 From: sckwon770 Date: Mon, 22 Apr 2024 01:36:38 +0900 Subject: [PATCH] =?UTF-8?q?[OING-317]=20refactor:=20=EB=B7=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20API=EB=A5=BC=20=EB=91=98=EB=9F=AC=EC=8B=BC=20?= =?UTF-8?q?=EA=B5=90=ED=86=B5=EC=A0=95=EB=A6=AC=201=20(#238)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add leftUploadCountUntilMissionUnlock, dailyMissionConten and Add debug parameter to control boolean flag * refactor: Integrate HomeAPI to MainViewController and Add getNighttimePage API * fix: Fix wrongly written get mapping url of getNighttimePage * fix: Add the missing GetMapping annotation and fix wrongly written swagger summary --- .../com/oing/controller/HomeController.java | 23 ---- ...ontroller.java => MainViewController.java} | 104 +++++++++++++----- ...Response.java => DaytimePageResponse.java} | 18 ++- .../FamilyMemberMonthlyRankingResponse.java | 6 +- .../dto/response/MainPageTopBarResponse.java | 4 +- .../dto/response/NighttimePageResponse.java | 15 +++ .../main/java/com/oing/restapi/HomeApi.java | 29 ----- .../java/com/oing/restapi/MainViewApi.java | 69 ++++++++++++ .../java/com/oing/restapi/ViewBasedApi.java | 29 ----- 9 files changed, 179 insertions(+), 118 deletions(-) delete mode 100644 gateway/src/main/java/com/oing/controller/HomeController.java rename gateway/src/main/java/com/oing/controller/{ViewBasedController.java => MainViewController.java} (64%) rename gateway/src/main/java/com/oing/dto/response/{MainPageResponse.java => DaytimePageResponse.java} (55%) create mode 100644 gateway/src/main/java/com/oing/dto/response/NighttimePageResponse.java delete mode 100644 gateway/src/main/java/com/oing/restapi/HomeApi.java create mode 100644 gateway/src/main/java/com/oing/restapi/MainViewApi.java delete mode 100644 gateway/src/main/java/com/oing/restapi/ViewBasedApi.java diff --git a/gateway/src/main/java/com/oing/controller/HomeController.java b/gateway/src/main/java/com/oing/controller/HomeController.java deleted file mode 100644 index 0a16c2b2..00000000 --- a/gateway/src/main/java/com/oing/controller/HomeController.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.oing.controller; - -import com.oing.dto.response.FamilyMemberMonthlyRankingResponse; -import com.oing.dto.response.FamilyMemberRankerResponse; -import com.oing.restapi.HomeApi; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Controller; - -@Controller -@RequiredArgsConstructor -public class HomeController implements HomeApi { - - @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); - } -} diff --git a/gateway/src/main/java/com/oing/controller/ViewBasedController.java b/gateway/src/main/java/com/oing/controller/MainViewController.java similarity index 64% rename from gateway/src/main/java/com/oing/controller/ViewBasedController.java rename to gateway/src/main/java/com/oing/controller/MainViewController.java index d7bf685e..950ab117 100644 --- a/gateway/src/main/java/com/oing/controller/ViewBasedController.java +++ b/gateway/src/main/java/com/oing/controller/MainViewController.java @@ -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.*; /** @@ -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 memberMap = new HashMap<>(); Page members = memberService.getFamilyMembersProfilesByFamilyId(familyId, 1, PAGE_FETCH_SIZE); members.forEach(member -> memberMap.put(member.memberId(), member)); @@ -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(), @@ -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( @@ -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( @@ -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 members = memberService.getFamilyMembersProfilesByFamilyId(loginFamilyId, 1, PAGE_FETCH_SIZE); + LocalDate today = ZonedDateTime.now().toLocalDate(); + List 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); + } } diff --git a/gateway/src/main/java/com/oing/dto/response/MainPageResponse.java b/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java similarity index 55% rename from gateway/src/main/java/com/oing/dto/response/MainPageResponse.java rename to gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java index 4607bfbf..b6c51015 100644 --- a/gateway/src/main/java/com/oing/dto/response/MainPageResponse.java +++ b/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java @@ -4,24 +4,30 @@ import java.util.List; -@Schema(description = "메인 페이지") -public record MainPageResponse( +@Schema(description = "주간 메인 페이지") +public record DaytimePageResponse( @Schema(description = "상단 바 요소") List topBarElements, + @Schema(description = "날 찌른 목록") + List 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 survivalFeeds, @Schema(description = "미션 피드 목록") - List missionFeeds, - - @Schema(description = "날 찌른 목록") - List pickers + List missionFeeds ) { } diff --git a/gateway/src/main/java/com/oing/dto/response/FamilyMemberMonthlyRankingResponse.java b/gateway/src/main/java/com/oing/dto/response/FamilyMemberMonthlyRankingResponse.java index 8f1f1f17..9672986a 100644 --- a/gateway/src/main/java/com/oing/dto/response/FamilyMemberMonthlyRankingResponse.java +++ b/gateway/src/main/java/com/oing/dto/response/FamilyMemberMonthlyRankingResponse.java @@ -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 ) { } diff --git a/gateway/src/main/java/com/oing/dto/response/MainPageTopBarResponse.java b/gateway/src/main/java/com/oing/dto/response/MainPageTopBarResponse.java index 42d20357..8fddd0f7 100644 --- a/gateway/src/main/java/com/oing/dto/response/MainPageTopBarResponse.java +++ b/gateway/src/main/java/com/oing/dto/response/MainPageTopBarResponse.java @@ -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") diff --git a/gateway/src/main/java/com/oing/dto/response/NighttimePageResponse.java b/gateway/src/main/java/com/oing/dto/response/NighttimePageResponse.java new file mode 100644 index 00000000..a4153ca5 --- /dev/null +++ b/gateway/src/main/java/com/oing/dto/response/NighttimePageResponse.java @@ -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 topBarElements, + + @Schema(description = "금월의 가족 구성원 월간 랭킹") + FamilyMemberMonthlyRankingResponse familyMemberMonthlyRanking +) { +} diff --git a/gateway/src/main/java/com/oing/restapi/HomeApi.java b/gateway/src/main/java/com/oing/restapi/HomeApi.java deleted file mode 100644 index 5cac25e2..00000000 --- a/gateway/src/main/java/com/oing/restapi/HomeApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.oing.restapi; - -import com.oing.dto.response.FamilyMemberMonthlyRankingResponse; -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 jakarta.validation.Valid; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Tag(name = "홈 View API", description = "프론트의 홈 화면 기반으로 작성된 View API") -@RestController -@Valid -@RequestMapping("/v1/home") -public interface HomeApi { - - @Operation(summary = "금월의 가족 구성원 월간 랭킹 조회", description = "이번 달에 해당하는 가족 구성원 월간 랭킹을 조회합니다.") - FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking( - @Parameter(hidden = true) - @LoginMemberId - String loginMemberId, - - @Parameter(hidden = true) - @LoginFamilyId - String loginFamilyId - ); -} diff --git a/gateway/src/main/java/com/oing/restapi/MainViewApi.java b/gateway/src/main/java/com/oing/restapi/MainViewApi.java new file mode 100644 index 00000000..8c969ed2 --- /dev/null +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -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 + ); +} diff --git a/gateway/src/main/java/com/oing/restapi/ViewBasedApi.java b/gateway/src/main/java/com/oing/restapi/ViewBasedApi.java deleted file mode 100644 index dcc1f9e1..00000000 --- a/gateway/src/main/java/com/oing/restapi/ViewBasedApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.oing.restapi; - -import com.oing.dto.response.MainPageResponse; -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.RestController; - -/** - * no5ing-server - * User: CChuYong - * Date: 4/16/24 - * Time: 4:01 PM - */ -@Tag(name = "뷰 기반 API") -@RestController -@RequestMapping("/v1/view") -public interface ViewBasedApi { - @Operation(summary = "메인 페이지 조회") - @GetMapping("/main") - MainPageResponse getMainPage( - @Parameter(hidden = true) - @LoginMemberId - String loginMemberId - ); -}