From 4b84e4c78cf5f744ec0ded68cd8a7f6547150c08 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Mon, 22 Apr 2024 00:56:14 +0900 Subject: [PATCH 1/4] feat: Add leftUploadCountUntilMissionUnlock, dailyMissionConten and Add debug parameter to control boolean flag --- ...ontroller.java => MainViewController.java} | 65 +++++++++++-------- ...Response.java => DaytimePageResponse.java} | 16 +++-- .../java/com/oing/restapi/MainViewApi.java | 40 ++++++++++++ .../java/com/oing/restapi/ViewBasedApi.java | 29 --------- 4 files changed, 90 insertions(+), 60 deletions(-) rename gateway/src/main/java/com/oing/controller/{ViewBasedController.java => MainViewController.java} (88%) rename gateway/src/main/java/com/oing/dto/response/{MainPageResponse.java => DaytimePageResponse.java} (59%) 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/ViewBasedController.java b/gateway/src/main/java/com/oing/controller/MainViewController.java similarity index 88% rename from gateway/src/main/java/com/oing/controller/ViewBasedController.java rename to gateway/src/main/java/com/oing/controller/MainViewController.java index d7bf685e..e12feb26 100644 --- a/gateway/src/main/java/com/oing/controller/ViewBasedController.java +++ b/gateway/src/main/java/com/oing/controller/MainViewController.java @@ -2,11 +2,8 @@ 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; @@ -23,15 +20,20 @@ */ @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); @@ -62,8 +64,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(), @@ -76,8 +81,31 @@ public MainPageResponse getMainPage( && !member.memberId().equals(loginMemberId) && !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 +115,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 +124,7 @@ 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() - ); } } 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 59% 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..27153fb4 100644 --- a/gateway/src/main/java/com/oing/dto/response/MainPageResponse.java +++ b/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java @@ -5,23 +5,29 @@ import java.util.List; @Schema(description = "메인 페이지") -public record MainPageResponse( +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/restapi/MainViewApi.java b/gateway/src/main/java/com/oing/restapi/MainViewApi.java new file mode 100644 index 00000000..9e6e35db --- /dev/null +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -0,0 +1,40 @@ +package com.oing.restapi; + +import com.oing.dto.response.DaytimePageResponse; +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 + ); +} 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 - ); -} From 807e04d7fd7f863f3627c20c6576b573d0af582f Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Mon, 22 Apr 2024 01:09:01 +0900 Subject: [PATCH 2/4] refactor: Integrate HomeAPI to MainViewController and Add getNighttimePage API --- .../com/oing/controller/HomeController.java | 23 ---------- .../oing/controller/MainViewController.java | 43 +++++++++++++++++-- .../dto/response/DaytimePageResponse.java | 2 +- .../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 | 28 ++++++++++++ 8 files changed, 90 insertions(+), 60 deletions(-) delete mode 100644 gateway/src/main/java/com/oing/controller/HomeController.java 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 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/MainViewController.java b/gateway/src/main/java/com/oing/controller/MainViewController.java index e12feb26..950ab117 100644 --- a/gateway/src/main/java/com/oing/controller/MainViewController.java +++ b/gateway/src/main/java/com/oing/controller/MainViewController.java @@ -10,6 +10,7 @@ import java.time.LocalDate; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.*; /** @@ -37,7 +38,7 @@ public DaytimePageResponse getDaytimePage( 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)); @@ -79,12 +80,12 @@ public DaytimePageResponse getDaytimePage( && member.dayOfBirth().getDayOfMonth() == today.getDayOfMonth(), !pickedSet.contains(member.memberId()) && !member.memberId().equals(loginMemberId) - && !postUploaderRankMap.containsKey(member.memberId()) + && !postUploaderRankMap.containsKey(member.memberId()) )).toList(), memberPickService.getPickMembers(familyId, loginMemberId).stream().map(pickMember -> { FamilyMemberProfileResponse member = memberMap.get(pickMember.getFromMemberId()); - if(member == null) { + if (member == null) { return new MainPagePickerResponse( pickMember.getFromMemberId(), "UNKNOWN", @@ -127,4 +128,40 @@ public DaytimePageResponse getDaytimePage( }).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/DaytimePageResponse.java b/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java index 27153fb4..b6c51015 100644 --- a/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java +++ b/gateway/src/main/java/com/oing/dto/response/DaytimePageResponse.java @@ -4,7 +4,7 @@ import java.util.List; -@Schema(description = "메인 페이지") +@Schema(description = "주간 메인 페이지") public record DaytimePageResponse( @Schema(description = "상단 바 요소") List topBarElements, 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 index 9e6e35db..a676d895 100644 --- a/gateway/src/main/java/com/oing/restapi/MainViewApi.java +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -1,6 +1,9 @@ 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; @@ -37,4 +40,29 @@ DaytimePageResponse getDaytimePage( @LoginMemberId String loginMemberId ); + + + @Operation(summary = "주간의 메인 페이지 조회") + @GetMapping("/daytime-page") + NighttimePageResponse getNighttimePage( + @Parameter(hidden = true) + @LoginMemberId + String loginMemberId, + + @Parameter(hidden = true) + @LoginFamilyId + String loginFamilyId + ); + + + @Operation(summary = "금월의 가족 구성원 월간 랭킹 조회", description = "이번 달에 해당하는 가족 구성원 월간 랭킹을 조회합니다.") + FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking( + @Parameter(hidden = true) + @LoginMemberId + String loginMemberId, + + @Parameter(hidden = true) + @LoginFamilyId + String loginFamilyId + ); } From e13330993a0e2ea77cfbbc308ef6ff09814dfc49 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Mon, 22 Apr 2024 01:21:29 +0900 Subject: [PATCH 3/4] fix: Fix wrongly written get mapping url of getNighttimePage --- gateway/src/main/java/com/oing/restapi/MainViewApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/src/main/java/com/oing/restapi/MainViewApi.java b/gateway/src/main/java/com/oing/restapi/MainViewApi.java index a676d895..87a1470d 100644 --- a/gateway/src/main/java/com/oing/restapi/MainViewApi.java +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -43,7 +43,7 @@ DaytimePageResponse getDaytimePage( @Operation(summary = "주간의 메인 페이지 조회") - @GetMapping("/daytime-page") + @GetMapping("/nighttime-page") NighttimePageResponse getNighttimePage( @Parameter(hidden = true) @LoginMemberId From 2cce08eaa2ac379609b1e7959f2cc6da4f9737e5 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Mon, 22 Apr 2024 01:34:08 +0900 Subject: [PATCH 4/4] fix: Add the missing GetMapping annotation and fix wrongly written swagger summary --- gateway/src/main/java/com/oing/restapi/MainViewApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gateway/src/main/java/com/oing/restapi/MainViewApi.java b/gateway/src/main/java/com/oing/restapi/MainViewApi.java index 87a1470d..8c969ed2 100644 --- a/gateway/src/main/java/com/oing/restapi/MainViewApi.java +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -42,7 +42,7 @@ DaytimePageResponse getDaytimePage( ); - @Operation(summary = "주간의 메인 페이지 조회") + @Operation(summary = "야간의 메인 페이지 조회") @GetMapping("/nighttime-page") NighttimePageResponse getNighttimePage( @Parameter(hidden = true) @@ -56,6 +56,7 @@ NighttimePageResponse getNighttimePage( @Operation(summary = "금월의 가족 구성원 월간 랭킹 조회", description = "이번 달에 해당하는 가족 구성원 월간 랭킹을 조회합니다.") + @GetMapping("/family-ranking") FamilyMemberMonthlyRankingResponse getFamilyMemberMonthlyRanking( @Parameter(hidden = true) @LoginMemberId