-
Notifications
You must be signed in to change notification settings - Fork 2
활동 기반 배지 구현 #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Junad-Park
wants to merge
3
commits into
feature/badge-list-and-representative
Choose a base branch
from
feature/activity-badges
base: feature/badge-list-and-representative
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
활동 기반 배지 구현 #165
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/im/toduck/domain/badge/domain/checker/CrowBadgeChecker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package im.toduck.domain.badge.domain.checker; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import im.toduck.domain.badge.persistence.entity.BadgeCode; | ||
| import im.toduck.domain.routine.persistence.repository.RoutineRepository; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * 까마귀 뱃지 체커: 기억력 카테고리(Routine Category) 5개 이상 사용 시 지급 | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CrowBadgeChecker implements BadgeConditionChecker { | ||
|
|
||
| private final RoutineRepository routineRepository; | ||
|
|
||
| @Override | ||
| public BadgeCode getBadgeCode() { | ||
| return BadgeCode.CROW; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkCondition(final User user) { | ||
| return routineRepository.countDistinctCategoryByUser(user) >= 5; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/main/java/im/toduck/domain/badge/domain/checker/DailyDiaryBadgeChecker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package im.toduck.domain.badge.domain.checker; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.YearMonth; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import im.toduck.domain.badge.persistence.entity.BadgeCode; | ||
| import im.toduck.domain.diary.persistence.repository.DiaryRepository; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * 하루일기 뱃지 체커: 감정일기 한 달 작성률 50% 이상 달성 시 지급 | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class DailyDiaryBadgeChecker implements BadgeConditionChecker { | ||
| private static final int FIRST_DAY_OF_MONTH = 1; | ||
| private static final double MINIMUM_WRITTEN_RATIO = 0.5; | ||
|
|
||
| private final DiaryRepository diaryRepository; | ||
|
|
||
| @Override | ||
| public BadgeCode getBadgeCode() { | ||
| return BadgeCode.DAILY_DIARY; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkCondition(final User user) { | ||
| YearMonth currentMonth = YearMonth.now(); | ||
| LocalDate startDate = currentMonth.atDay(FIRST_DAY_OF_MONTH); | ||
| LocalDate endDate = currentMonth.atEndOfMonth(); | ||
| int daysInMonth = currentMonth.lengthOfMonth(); | ||
|
|
||
| long writtenDays = diaryRepository.countDistinctDateByUserAndDateBetween(user, startDate, endDate); | ||
|
|
||
| return writtenDays >= daysInMonth * MINIMUM_WRITTEN_RATIO; | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
src/main/java/im/toduck/domain/badge/domain/checker/FocusGeniusBadgeChecker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package im.toduck.domain.badge.domain.checker; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import im.toduck.domain.badge.persistence.entity.BadgeCode; | ||
| import im.toduck.domain.concentration.persistence.repository.ConcentrationRepository; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * 집중천재 뱃지 체커: 타이머 15회 이상 사용 시 지급 | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class FocusGeniusBadgeChecker implements BadgeConditionChecker { | ||
|
|
||
| private final ConcentrationRepository concentrationRepository; | ||
|
|
||
| @Override | ||
| public BadgeCode getBadgeCode() { | ||
| return BadgeCode.FOCUS_GENIUS; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkCondition(final User user) { | ||
| return concentrationRepository.sumTargetCountByUser(user) >= 15; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/im/toduck/domain/badge/domain/checker/PerfectionistBadgeChecker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package im.toduck.domain.badge.domain.checker; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import im.toduck.domain.badge.persistence.entity.BadgeCode; | ||
| import im.toduck.domain.routine.persistence.repository.RoutineRepository; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * 완벽주의 뱃지 체커: 루틴 10개 이상 등록 시 지급 | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class PerfectionistBadgeChecker implements BadgeConditionChecker { | ||
|
|
||
| private final RoutineRepository routineRepository; | ||
|
|
||
| @Override | ||
| public BadgeCode getBadgeCode() { | ||
| return BadgeCode.PERFECTIONIST; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkCondition(final User user) { | ||
| return routineRepository.countByUserAndDeletedAtIsNull(user) >= 10; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/im/toduck/domain/badge/domain/checker/QuackQuackBadgeChecker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package im.toduck.domain.badge.domain.checker; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import im.toduck.domain.badge.persistence.entity.BadgeCode; | ||
| import im.toduck.domain.social.persistence.repository.SocialRepository; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * 꽥꽥 뱃지 체커: 소셜 글 15개 이상 작성 시 지급 | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class QuackQuackBadgeChecker implements BadgeConditionChecker { | ||
|
|
||
| private final SocialRepository socialRepository; | ||
|
|
||
| @Override | ||
| public BadgeCode getBadgeCode() { | ||
| return BadgeCode.QUACK_QUACK; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkCondition(final User user) { | ||
| return socialRepository.countByUserId(user.getId()) >= 15; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/im/toduck/domain/concentration/domain/event/ConcentrationSavedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package im.toduck.domain.concentration.domain.event; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class ConcentrationSavedEvent { | ||
| private final Long userId; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/im/toduck/domain/diary/domain/event/DiaryCreatedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package im.toduck.domain.diary.domain.event; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class DiaryCreatedEvent { | ||
| private final Long userId; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/im/toduck/domain/social/domain/event/SocialCreatedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package im.toduck.domain.social.domain.event; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class SocialCreatedEvent { | ||
| private final Long userId; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p4:
YearMonth.now()를 직접 호출하고 있어서, 월말/월초 경계에서 테스트가 flaky해질 가능성이 있지 않을까요?예를 들어 테스트가 1월 31일 23:59에 시작되었는데 실제 쿼리 시점에 2월 1일로 넘어가면,
now()가 반환하는 월과 DB에 넣은 데이터의 월이 달라져서 테스트가 실패할 수 있을 것 같아요. 또한 2월(28일)과 7월(31일)에서 50% 기준 일수가 다르기 때문에 특정 월에서만 실패하는 케이스도 생길 수 있고요.당장은 큰 문제가 없어 보여서 참고차 남깁니다..!