From d66fc04c689b27a6340d8fef21aec43e3743c404 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 21 Apr 2024 17:48:28 +0900 Subject: [PATCH 1/8] feature: add getSurvivalUploadStatus API logic --- post/src/main/java/com/oing/controller/PostController.java | 7 +++---- post/src/main/java/com/oing/restapi/PostApi.java | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/post/src/main/java/com/oing/controller/PostController.java b/post/src/main/java/com/oing/controller/PostController.java index 8b3264d0..213c4bd6 100644 --- a/post/src/main/java/com/oing/controller/PostController.java +++ b/post/src/main/java/com/oing/controller/PostController.java @@ -91,11 +91,10 @@ public PostResponse getPost(String postId, String loginMemberId) { } @Override - public SurvivalUploadStatusResponse getSurvivalUploadStatus(String memberId, String loginMemberId, boolean valid) { + public SurvivalUploadStatusResponse getSurvivalUploadStatus(String memberId, String loginMemberId, String loginFamilyId) { validateMemberId(loginMemberId, memberId); - // TODO: 추후 valid 파라미터 삭제 - // TODO: 해당 회원이 생존신고 글을 올렸는지 검증 로직 추가 - if (valid) { + + if (postService.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, loginFamilyId, PostType.SURVIVAL, LocalDate.now())) { return new SurvivalUploadStatusResponse(true); } return new SurvivalUploadStatusResponse(false); diff --git a/post/src/main/java/com/oing/restapi/PostApi.java b/post/src/main/java/com/oing/restapi/PostApi.java index 0e467b50..57eb5081 100644 --- a/post/src/main/java/com/oing/restapi/PostApi.java +++ b/post/src/main/java/com/oing/restapi/PostApi.java @@ -125,9 +125,9 @@ SurvivalUploadStatusResponse getSurvivalUploadStatus( @LoginMemberId String loginMemberId, - @RequestParam - @Parameter(description = "응답 값 조작 필드", example = "true") - boolean valid + @Parameter(hidden = true) + @LoginFamilyId + String loginFamilyId ); @Operation(summary = "회원 미션 참여 가능 여부 응답 조회", description = "회원 미션 참여 가능 여부를 조회합니다.") From cdefae868e4d40eef4376cf01bd2a89e8465591f Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:23:35 +0900 Subject: [PATCH 2/8] feature: add getMissionAvailableStatus API --- .../repository/PostRepositoryCustomImpl.java | 21 +++++++++++++++++++ .../com/oing/controller/PostController.java | 9 ++++---- .../MissionAvailableStatusResponse.java | 4 ++-- .../oing/repository/PostRepositoryCustom.java | 1 + .../main/java/com/oing/restapi/PostApi.java | 6 +++--- .../java/com/oing/service/PostService.java | 4 ++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java index a05c16f6..f265131a 100644 --- a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java +++ b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java @@ -116,6 +116,27 @@ public boolean existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(String memberId, S .fetchFirst() != null; } + @Override + public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) { + long totalFamilyMembers = queryFactory + .select(member.count()) + .from(member) + .where(member.familyId.eq(familyId)) + .fetchFirst(); + + long survivalPostCount = queryFactory + .select(post.count()) + .from(post) + .where( + post.familyId.eq(familyId), + post.type.eq(PostType.SURVIVAL), + dateExpr(post.createdAt).eq(date) + ) + .fetchFirst(); + + return survivalPostCount >= Math.floor(totalFamilyMembers / 2); + } + private DateTimeTemplate dateExpr(DateTimePath localDateTime) { return Expressions.dateTimeTemplate(LocalDate.class, "DATE({0})", localDateTime); } diff --git a/post/src/main/java/com/oing/controller/PostController.java b/post/src/main/java/com/oing/controller/PostController.java index 213c4bd6..e58a2e65 100644 --- a/post/src/main/java/com/oing/controller/PostController.java +++ b/post/src/main/java/com/oing/controller/PostController.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Controller; import java.time.LocalDate; +import java.time.ZonedDateTime; /** * no5ing-server @@ -101,11 +102,11 @@ public SurvivalUploadStatusResponse getSurvivalUploadStatus(String memberId, Str } @Override - public MissionAvailableStatusResponse getMissionAvailableStatus(String memberId, String loginMemberId, boolean valid) { + public MissionAvailableStatusResponse getMissionAvailableStatus(String memberId, String loginMemberId, String loginFamilyId) { validateMemberId(loginMemberId, memberId); - // TODO: 추후 valid 파라미터 삭제 - // TODO: 해당 회원이 미션에 참여 가능한 회원인지 검증 로직 추가 - if (valid) { + LocalDate today = ZonedDateTime.now().toLocalDate(); + + if (postService.isCreatedSurvivalPostByMajority(today, loginFamilyId)) { return new MissionAvailableStatusResponse(true); } return new MissionAvailableStatusResponse(false); diff --git a/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java b/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java index 5731366f..46a1417d 100644 --- a/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java +++ b/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java @@ -2,9 +2,9 @@ import io.swagger.v3.oas.annotations.media.Schema; -@Schema(description = "회원 미션 참여 가능 여부 응답") +@Schema(description = "가족 미션 참여 가능 (미션 키) 여부 응답") public record MissionAvailableStatusResponse( - @Schema(description = "회원 미션 참여 가능 여부", example = "true") + @Schema(description = "가족 미션 참여 가능 (미션 키) 여부", example = "true") boolean isAvailable ) { } diff --git a/post/src/main/java/com/oing/repository/PostRepositoryCustom.java b/post/src/main/java/com/oing/repository/PostRepositoryCustom.java index 15819868..d0010f60 100644 --- a/post/src/main/java/com/oing/repository/PostRepositoryCustom.java +++ b/post/src/main/java/com/oing/repository/PostRepositoryCustom.java @@ -22,4 +22,5 @@ QueryResults searchPosts(int page, int size, LocalDate date, String member boolean existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(String memberId, String familyId, PostType type, LocalDate postDate); + boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId); } diff --git a/post/src/main/java/com/oing/restapi/PostApi.java b/post/src/main/java/com/oing/restapi/PostApi.java index 57eb5081..6adbbdcb 100644 --- a/post/src/main/java/com/oing/restapi/PostApi.java +++ b/post/src/main/java/com/oing/restapi/PostApi.java @@ -141,8 +141,8 @@ MissionAvailableStatusResponse getMissionAvailableStatus( @LoginMemberId String loginMemberId, - @RequestParam - @Parameter(description = "응답 값 조작 필드", example = "true") - boolean valid + @Parameter(hidden = true) + @LoginFamilyId + String loginFamilyId ); } diff --git a/post/src/main/java/com/oing/service/PostService.java b/post/src/main/java/com/oing/service/PostService.java index 6f01c2ab..0715f946 100644 --- a/post/src/main/java/com/oing/service/PostService.java +++ b/post/src/main/java/com/oing/service/PostService.java @@ -160,4 +160,8 @@ public boolean existsByFamilyIdAndCreatedAt(String familyId, LocalDate postDate) public boolean existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(String memberId, String familyId, PostType type, LocalDate postDate) { return postRepository.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, type, postDate); } + + public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) { + return postRepository.isCreatedSurvivalPostByMajority(date, familyId); + } } From d99eb6ad1fd9796c96d8df2f297c884c8cd04cb1 Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:28:12 +0900 Subject: [PATCH 3/8] test: add getMissionAvailable Repository Test --- .../repository/PostRepositoryCustomTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java b/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java index be927cd2..2a245339 100644 --- a/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java +++ b/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java @@ -127,4 +127,30 @@ void setup() { // then assertThat(exists).isFalse(); } + + @Test + void 미션_키_획득한_날짜에_가족의_미션_키_획득_여부를_조회한다() { + // given + String familyId = testMember1.getFamilyId(); + LocalDate today = LocalDate.of(2023, 11, 1); + + // when + boolean exists = postRepositoryCustomImpl.isCreatedSurvivalPostByMajority(today, familyId); + + // then + assertThat(exists).isTrue(); + } + + @Test + void 미션_키_획득하지_못한_날짜에_가족의_미션_키_획득_여부를_조회한다() { + // given + String familyId = testMember1.getFamilyId(); + LocalDate today = LocalDate.of(2024, 4, 1); + + // when + boolean exists = postRepositoryCustomImpl.isCreatedSurvivalPostByMajority(today, familyId); + + // then + assertThat(exists).isFalse(); + } } From bc4fb142e284016fd0afc7afe88dfdcc826a3b4e Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:34:11 +0900 Subject: [PATCH 4/8] test: add getMissionAvailable and getSurvivalUploadStatus Api Test --- .../java/com/oing/restapi/PostApiTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gateway/src/test/java/com/oing/restapi/PostApiTest.java b/gateway/src/test/java/com/oing/restapi/PostApiTest.java index 652f1438..2846da88 100644 --- a/gateway/src/test/java/com/oing/restapi/PostApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/PostApiTest.java @@ -148,4 +148,42 @@ void setUp() { .andExpect(jsonPath("$.results[0].authorId").value(TEST_MEMBER1_ID)) .andExpect(jsonPath("$.results[0].content").value("content")); } + + @Test + void 회원_생존신고_게시글_업로드_여부_조회_테스트() throws Exception { + //given + postRepository.save(new Post(TEST_POST_ID, TEST_MEMBER1_ID, TEST_FAMILY_ID, PostType.SURVIVAL, "img", "img", + "content")); + + //when + ResultActions resultActions = mockMvc.perform( + get("/v1/posts/{memberId}/survival-uploaded", TEST_MEMBER1_ID) + .header("X-AUTH-TOKEN", TEST_MEMBER1_TOKEN) + .contentType(MediaType.APPLICATION_JSON) + ); + + //then + resultActions + .andExpect(status().isOk()) + .andExpect(jsonPath("$.isValid").value(true)); + } + + @Test + void 해당_가족의_미션_키_획득_여부_조회_테스트() throws Exception { + //given + postRepository.save(new Post(TEST_POST_ID, TEST_MEMBER1_ID, TEST_FAMILY_ID, PostType.SURVIVAL, "img", "img", + "content")); + + //when + ResultActions resultActions = mockMvc.perform( + get("/v1/posts/{memberId}/mission-available", TEST_MEMBER1_ID) + .header("X-AUTH-TOKEN", TEST_MEMBER1_TOKEN) + .contentType(MediaType.APPLICATION_JSON) + ); + + //then + resultActions + .andExpect(status().isOk()) + .andExpect(jsonPath("$.isAvailable").value(true)); + } } From 81830835bb4f963ebc02b3a2251eae09de344ba2 Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:40:56 +0900 Subject: [PATCH 5/8] style: change response dto field name --- gateway/src/test/java/com/oing/restapi/PostApiTest.java | 4 ++-- .../com/oing/dto/response/MissionAvailableStatusResponse.java | 2 +- .../com/oing/dto/response/SurvivalUploadStatusResponse.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gateway/src/test/java/com/oing/restapi/PostApiTest.java b/gateway/src/test/java/com/oing/restapi/PostApiTest.java index 2846da88..211ff5b3 100644 --- a/gateway/src/test/java/com/oing/restapi/PostApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/PostApiTest.java @@ -165,7 +165,7 @@ void setUp() { //then resultActions .andExpect(status().isOk()) - .andExpect(jsonPath("$.isValid").value(true)); + .andExpect(jsonPath("$.isMeUploadedToday").value(true)); } @Test @@ -184,6 +184,6 @@ void setUp() { //then resultActions .andExpect(status().isOk()) - .andExpect(jsonPath("$.isAvailable").value(true)); + .andExpect(jsonPath("$.isMissionUnlocked").value(true)); } } diff --git a/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java b/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java index 46a1417d..cacf126f 100644 --- a/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java +++ b/post/src/main/java/com/oing/dto/response/MissionAvailableStatusResponse.java @@ -5,6 +5,6 @@ @Schema(description = "가족 미션 참여 가능 (미션 키) 여부 응답") public record MissionAvailableStatusResponse( @Schema(description = "가족 미션 참여 가능 (미션 키) 여부", example = "true") - boolean isAvailable + boolean isMissionUnlocked ) { } diff --git a/post/src/main/java/com/oing/dto/response/SurvivalUploadStatusResponse.java b/post/src/main/java/com/oing/dto/response/SurvivalUploadStatusResponse.java index a53de652..db096fdc 100644 --- a/post/src/main/java/com/oing/dto/response/SurvivalUploadStatusResponse.java +++ b/post/src/main/java/com/oing/dto/response/SurvivalUploadStatusResponse.java @@ -6,6 +6,6 @@ @Schema(description = "회원 생존신고 게시글 업로드 여부 응답") public record SurvivalUploadStatusResponse( @Schema(description = "회원 생존신고 게시글 업로드 여부", example = "true") - boolean isValid + boolean isMeUploadedToday ) { } From a2903b353377036f6ca4b9c17dbd8549201f4c0a Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:46:02 +0900 Subject: [PATCH 6/8] feature: add getMissionAvailableStatus and getSurvivalUploadStatus logic to getDaytimePage --- .../java/com/oing/controller/MainViewController.java | 7 +++++-- .../src/main/java/com/oing/restapi/MainViewApi.java | 10 ---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/MainViewController.java b/gateway/src/main/java/com/oing/controller/MainViewController.java index 950ab117..192d804d 100644 --- a/gateway/src/main/java/com/oing/controller/MainViewController.java +++ b/gateway/src/main/java/com/oing/controller/MainViewController.java @@ -28,13 +28,12 @@ public class MainViewController implements MainViewApi { private final MemberPickService memberPickService; private final MemberBridge memberBridge; private final MissionBridge missionBridge; + private final PostController postController; private static final int PAGE_FETCH_SIZE = 1000; @Override public DaytimePageResponse getDaytimePage( - boolean isMissionUnlocked, - boolean isMeUploadedToday, String loginMemberId ) { String familyId = memberBridge.getFamilyIdByMemberId(loginMemberId); @@ -67,6 +66,10 @@ public DaytimePageResponse getDaytimePage( String todayMissionId = missionBridge.getTodayMissionId(); String dailyMissionContent = missionBridge.getContentByMissionId(todayMissionId); + boolean isMissionUnlocked = postController.getMissionAvailableStatus(loginMemberId, loginMemberId, familyId) + .isMissionUnlocked(); + boolean isMeUploadedToday = postController.getSurvivalUploadStatus(loginMemberId, loginMemberId, familyId) + .isMeUploadedToday(); return new DaytimePageResponse( diff --git a/gateway/src/main/java/com/oing/restapi/MainViewApi.java b/gateway/src/main/java/com/oing/restapi/MainViewApi.java index 8c969ed2..31c8b669 100644 --- a/gateway/src/main/java/com/oing/restapi/MainViewApi.java +++ b/gateway/src/main/java/com/oing/restapi/MainViewApi.java @@ -10,7 +10,6 @@ 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; /** @@ -27,15 +26,6 @@ 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 From d769a5e6b746e329a97acf21a238ebf39b676f5f Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 17:55:13 +0900 Subject: [PATCH 7/8] refactor: correct anti code --- .../main/java/com/oing/repository/PostRepositoryCustomImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java index f265131a..b800aac0 100644 --- a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java +++ b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java @@ -134,7 +134,7 @@ public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) ) .fetchFirst(); - return survivalPostCount >= Math.floor(totalFamilyMembers / 2); + return survivalPostCount >= totalFamilyMembers / 2; } private DateTimeTemplate dateExpr(DateTimePath localDateTime) { From 8ff4a59ae0adab2d1f343e4c39a10316373a96ef Mon Sep 17 00:00:00 2001 From: jisu Date: Wed, 24 Apr 2024 18:31:31 +0900 Subject: [PATCH 8/8] refactor: add member.deletedAt.isNull condition to isCreatedSurvivalPostByMajority --- .../java/com/oing/repository/PostRepositoryCustomImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java index b800aac0..6ae2d170 100644 --- a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java +++ b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java @@ -121,7 +121,8 @@ public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) long totalFamilyMembers = queryFactory .select(member.count()) .from(member) - .where(member.familyId.eq(familyId)) + .where(member.familyId.eq(familyId) + .and(member.deletedAt.isNull())) .fetchFirst(); long survivalPostCount = queryFactory