Skip to content

Commit

Permalink
[HOTFIX] hotfix: v1.1.4 버그 긴급 핫픽스 (#161)
Browse files Browse the repository at this point in the history
* hotfix: fix missing validation

* hotfix: fix collection issue of notification

* hotfix: add memberId validation

* refactor: Integrate the allFamilyMembersUploaded calculation logice between calendar and banner by ignoring withdrawn member

* fix: Fix getBanner not to calculate date when there is no family as allFamilyMembersUploaded day

* chore: Improve comment of getBanner API

---------

Co-authored-by: 송영민 <[email protected]>
  • Loading branch information
Kwon770 and CChuYong authored Feb 11, 2024
1 parent ee99f79 commit ab047b4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
27 changes: 19 additions & 8 deletions gateway/src/main/java/com/oing/controller/CalendarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,35 @@ public BannerResponse getBanner(String yearMonth, String familyId) {
int allFamilyMembersUploadedStreaks = 0;
boolean allFamilyMembersUploadedStreaked = true;

// 한 달 동안 '가족이 전부 올린 날'과 '가족이 전부 올린 날의 연속'을 계산하기 위해, 1일부터 마지막 날까지 순회한다.
// 한 달 동안 '가족이 전부 업로드한 날'과 '전부 업로드한 날의 연속'을 계산하기 위해, 1일부터 마지막 날까지 순회한다.
while (startDate.isBefore(endDate)) {
List<String> familyMembersIds = memberService.findFamilyMembersIdsByFamilyJoinAtBefore(familyId, startDate.plusDays(1));
boolean allFamilyMembersUploaded = true;
for (String memberId : familyMembersIds) {
if (!memberPostService.existsByMemberIdAndFamilyIdAndCreatedAt(memberId, familyId, startDate)) {
allFamilyMembersUploaded = false;
break;

if (memberPostService.existsByFamilyIdAndCreatedAt(familyId, startDate)) {
List<String> familyMembersIds = memberService.findFamilyMembersIdsByFamilyJoinAtBefore(familyId, startDate.plusDays(1));
for (String memberId : familyMembersIds) {
if (!memberPostService.existsByMemberIdAndFamilyIdAndCreatedAt(memberId, familyId, startDate)) {
allFamilyMembersUploaded = false;
break;
}
}

} else {
// 게시글이 없다면, 계산에서 제외
// 해당 날짜에 가족과 게시물이 없는 경우, allFamilyMembersUploaded = true 가 되는 것을 방지
// edge case: 게시물을 하나라도 없로드 하고 글을 업로드하지 않은 회원이 탈퇴하면, allFamilyMembersUploaded이 true로 변함 -> 핸들링할 수 없는 케이스
allFamilyMembersUploaded = false;
}


// (가족 전부 업로드한 날의 수, 연속해서 업로드한 여부, 연속해서 업로드한 날의 수) 계산
if (allFamilyMembersUploaded) {
allFamilyMembersUploadedDays++;

if (allFamilyMembersUploadedStreaked)
allFamilyMembersUploadedStreaks++; // 가족 전체 업로드가 연속되면, Streak + 1
allFamilyMembersUploadedStreaks++;
} else {
allFamilyMembersUploadedStreaked = false; // 가족 전체 업로드가 연속되지 못하면, Streak false
allFamilyMembersUploadedStreaked = false;
}

startDate = startDate.plusDays(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.querydsl.core.types.Ops;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.DateTimePath;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.core.types.dsl.DateTimeTemplate;
Expand Down Expand Up @@ -86,16 +87,31 @@ private BooleanExpression eqMemberId(String memberId) {
}

@Override
public boolean existsByMemberIdAndFamilyIdAndCreatedAt(String memberId, String familyId, LocalDate postDate) {
DateTimeTemplate<LocalDate> createdAtDate = Expressions.dateTimeTemplate(LocalDate.class,
"DATE({0})", memberPost.createdAt);
public boolean existsByFamilyIdAndCreatedAt(String familyId, LocalDate postDate) {
return queryFactory
.select(memberPost.id)
.from(memberPost)
.where(
memberPost.familyId.eq(familyId),
dateExpr(memberPost.createdAt).eq(postDate)
)
.fetchFirst() != null;
}

@Override
public boolean existsByMemberIdAndFamilyIdAndCreatedAt(String memberId, String familyId, LocalDate postDate) {
return queryFactory
.select(memberPost.id)
.from(memberPost)
.where(memberPost.memberId.eq(memberId)
.and(memberPost.familyId.eq(familyId))
.and(createdAtDate.eq(postDate)))
.where(
memberPost.memberId.eq(memberId),
memberPost.familyId.eq(familyId),
dateExpr(memberPost.createdAt).eq(postDate)
)
.fetchFirst() != null;
}

private DateTimeTemplate<LocalDate> dateExpr(DateTimePath<LocalDateTime> localDateTime) {
return Expressions.dateTimeTemplate(LocalDate.class, "DATE({0})", localDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ public interface MemberPostRepositoryCustom {

long countMonthlyPostByFamilyId(int year, int month, String familyId);

boolean existsByFamilyIdAndCreatedAt(String familyId, LocalDate postDate);

boolean existsByMemberIdAndFamilyIdAndCreatedAt(String memberId, String familyId, LocalDate postDate);

}
4 changes: 4 additions & 0 deletions post/src/main/java/com/oing/service/MemberPostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public List<String> getMemberIdsPostedToday(LocalDate date) {
return memberPostRepository.getMemberIdsPostedToday(date);
}

public boolean existsByFamilyIdAndCreatedAt(String familyId, LocalDate postDate) {
return memberPostRepository.existsByFamilyIdAndCreatedAt(familyId, postDate);
}

public boolean existsByMemberIdAndFamilyIdAndCreatedAt(String memberId, String familyId, LocalDate postDate) {
return memberPostRepository.existsByMemberIdAndFamilyIdAndCreatedAt(memberId, familyId, postDate);
}
Expand Down

0 comments on commit ab047b4

Please sign in to comment.