Repository navigation
[Feat] 알림 이벤트 추가 #120
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
[Feat] 알림 이벤트 추가 #120
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,16 @@ | |
| import com.mr.domain.user.entity.User; | ||
| import com.mr.domain.user.repository.UserRepository; | ||
| import com.mr.global.apipayload.exception.GeneralException; | ||
| import com.mr.global.event.NotificationEvent; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.Clock; | ||
| import java.time.DayOfWeek; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import static com.mr.domain.backingtrack.entity.enums.AccessLevel.PUBLIC; | ||
|
|
@@ -32,6 +38,10 @@ public class PlayingService { | |
| private final UserRepository userRepository; | ||
| private final BackingTrackRepository backingTrackRepository; | ||
|
|
||
| private final ApplicationEventPublisher eventPublisher; | ||
|
|
||
| private final Clock clock; | ||
|
|
||
| @Transactional | ||
| public PlayingStartResponse startPlaying( | ||
| Long userId, PlayingStartRequest request | ||
|
|
@@ -80,6 +90,29 @@ public MidiEventSaveResponse saveMidiEvents( | |
|
|
||
| playing.completeWithMidiData(midiEvents); | ||
|
|
||
| int intervalHours = 10; // 10시간 단위로 알림 | ||
| int intervalSeconds = intervalHours * 3600; | ||
|
|
||
| LocalDateTime weekStart = LocalDate.now(clock).with(DayOfWeek.MONDAY).atStartOfDay(); | ||
|
|
||
| // 방금 끝낸 연주를 제외한 이전 누적 시간 | ||
| Long previousWeeklySeconds = playingRepository.sumDurationSecExcludeCurrent( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P3 문제상황: 주간 연습 시간 마일스톤 계산이 문제가 되는 이유: 같은 유저가 서로 다른 연주 세션 두 개를 거의 동시에 완료( 수정 방향: 알림 자체가 크리티컬한 데이터는 아니라서 지금 당장 락을 걸 정도는 아니라고 봅니다. 다만 실제로 중복 알림이 이슈가 되면, Tip: 발생 확률이 낮고(정확히 같은 유저가 10시간 단위 경계를 걸치는 두 세션을 동시에 완료해야 함) 영향도도 낮아서(푸시 알림 한 번 더 가는 정도), 이번 PR을 막을 이슈는 아니라고 생각합니다. 그냥 참고만 하시면 될 것 같아요. |
||
| userId, playing.getStatus(), weekStart, playing.getId() | ||
| ); | ||
|
|
||
| Long currentDuration = playing.getDurationSec() != null ? playing.getDurationSec() : 0L; | ||
| Long totalWeeklySeconds = previousWeeklySeconds + currentDuration; | ||
|
|
||
| Long previousMilestones = previousWeeklySeconds / intervalSeconds; | ||
| Long currentMilestones = totalWeeklySeconds / intervalSeconds; | ||
|
|
||
| if (currentMilestones > previousMilestones) { | ||
| int achievedHours = (int)(currentMilestones * intervalHours); // 달성한 시간: 10 시간 단위 | ||
| eventPublisher.publishEvent( | ||
| NotificationEvent.forPractice(userId, playing.getUser().getNickname(), achievedHours) | ||
| ); | ||
| } | ||
|
|
||
| return MidiEventSaveResponse.of( | ||
| playing.getId(), | ||
| playing.getMidiData().size() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.