Skip to content

Commit

Permalink
Merge pull request #4 from depromeet/dev
Browse files Browse the repository at this point in the history
Fork Sync: Update from parent repository
  • Loading branch information
github-actions[bot] authored May 6, 2024
2 parents e8658fe + 8ab18d4 commit 060b0d0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,13 @@ public boolean existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(String memberId, S
}

@Override
public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) {
long totalFamilyMembers = queryFactory
.select(member.count())
.from(member)
.where(member.familyId.eq(familyId)
.and(isActiveMember()))
.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 >= totalFamilyMembers / 2;
}

@Override
public int countFamilyMembersByFamilyId(String familyId) {
public int countFamilyMembersByFamilyIdAtYesterday(String familyId) {
LocalDate today = ZonedDateTime.now().toLocalDate();
Long count = queryFactory
.select(member.id.count())
.from(member)
.where(member.familyId.eq(familyId)
.and(dateExpr(member.familyJoinAt).before(today))
.and(isActiveMember()))
.fetchFirst();
return count.intValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PostRepositoryCustomTest {
"testMember1",
"profile.com/1",
"1",
LocalDateTime.now()
LocalDateTime.now().minusDays(1)
);

private final Member testMember2 = new Member(
Expand All @@ -56,7 +56,7 @@ class PostRepositoryCustomTest {
"testMember2",
"profile.com/2",
"2",
LocalDateTime.now()
LocalDateTime.now().minusDays(1)
);

private final Member testMember3 = new Member(
Expand All @@ -65,7 +65,17 @@ class PostRepositoryCustomTest {
LocalDate.of(1999, 10, 18),
"testMember3",
"profile.com/3",
"2",
"3",
LocalDateTime.now().minusDays(1)
);

private final Member testMember4 = new Member(
"testMember4",
"testFamily",
LocalDate.of(1999, 10, 18),
"testMember4",
"profile.com/4",
"4",
LocalDateTime.now()
);

Expand Down Expand Up @@ -128,32 +138,6 @@ void setup() {
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();
}

@Test
void 해당_가족_구성원이_오늘_올린_생존신고_게시글_수를_조회한다() {
// given
Expand All @@ -167,12 +151,12 @@ void setup() {
}

@Test
void 가족_구성원_수를_조회한다() {
void 어제_날짜를_기준으로_가족_구성원_수를_조회한다() {
// given
String familyId = testMember1.getFamilyId();

// when
int familyMemberCount = postRepositoryCustomImpl.countFamilyMembersByFamilyId(familyId);
int familyMemberCount = postRepositoryCustomImpl.countFamilyMembersByFamilyIdAtYesterday(familyId);

// then
assertThat(familyMemberCount).isEqualTo(2);
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/test/java/com/oing/restapi/PostApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void setUp() {
TEST_FAMILY_ID,
LocalDate.now(),
"", "", "",
LocalDateTime.now()
LocalDateTime.now().minusDays(1)
)
);
TEST_MEMBER1_TOKEN = tokenGenerator
Expand All @@ -82,7 +82,7 @@ void setUp() {
TEST_FAMILY_ID,
LocalDate.now(),
"", "", "",
LocalDateTime.now()
LocalDateTime.now().minusDays(1)
)
);
TEST_MEMBER2_TOKEN = tokenGenerator
Expand Down
3 changes: 1 addition & 2 deletions post/src/main/java/com/oing/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ public MissionUploadStatusResponse getMissionUploadStatus(String memberId, Strin
@Override
public MissionAvailableStatusResponse getMissionAvailableStatus(String memberId, String loginMemberId, String loginFamilyId) {
validateMemberId(loginMemberId, memberId);
LocalDate today = ZonedDateTime.now().toLocalDate();

if (postService.isCreatedSurvivalPostByMajority(today, loginFamilyId)) {
if (postService.isCreatedSurvivalPostByMajority(loginFamilyId)) {
return new MissionAvailableStatusResponse(true);
}
return new MissionAvailableStatusResponse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ QueryResults<Post> 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);

int countFamilyMembersByFamilyId(String familyId);
int countFamilyMembersByFamilyIdAtYesterday(String familyId);

int countTodaySurvivalPostsByFamilyId(String familyId);
}
2 changes: 1 addition & 1 deletion post/src/main/java/com/oing/restapi/PostApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ MissionUploadStatusResponse getMissionUploadStatus(
String loginFamilyId
);

@Operation(summary = "회원 미션 참여 가능 여부 응답 조회", description = "회원 미션 참여 가능 여부를 조회합니다.")
@Operation(summary = "가족 미션 키 획득 여부 응답 조회", description = "가족 미션 키 획득 여부를 조회합니다.")
@GetMapping("/{memberId}/mission-available")
MissionAvailableStatusResponse getMissionAvailableStatus(
@PathVariable
Expand Down
9 changes: 6 additions & 3 deletions post/src/main/java/com/oing/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ public boolean existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(String memberId, S
return postRepository.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, type, postDate);
}

public boolean isCreatedSurvivalPostByMajority(LocalDate date, String familyId) {
return postRepository.isCreatedSurvivalPostByMajority(date, familyId);
public boolean isCreatedSurvivalPostByMajority(String familyId) {
int totalFamilyMembers = postRepository.countFamilyMembersByFamilyIdAtYesterday(familyId);
int survivalPostCount = postRepository.countTodaySurvivalPostsByFamilyId(familyId);

return survivalPostCount >= totalFamilyMembers / 2;
}

public int calculateRemainingSurvivalPostCountUntilMissionUnlocked(String familyId) {
int familyMemberCount = postRepository.countFamilyMembersByFamilyId(familyId);
int familyMemberCount = postRepository.countFamilyMembersByFamilyIdAtYesterday(familyId);
int requiredSurvivalPostCount = familyMemberCount / 2;
int todaySurvivalPostCount = postRepository.countTodaySurvivalPostsByFamilyId(familyId);

Expand Down
2 changes: 1 addition & 1 deletion post/src/test/java/com/oing/service/PostServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PostServiceTest {
String familyId = "1";

//when
when(postRepository.countFamilyMembersByFamilyId(familyId)).thenReturn(1);
when(postRepository.countFamilyMembersByFamilyIdAtYesterday(familyId)).thenReturn(1);
when(postRepository.countTodaySurvivalPostsByFamilyId(familyId)).thenReturn(0);

//then
Expand Down

0 comments on commit 060b0d0

Please sign in to comment.