Skip to content

chore : 최대 집중시간 3시간 설정#87

Merged
Juhye0k merged 1 commit intodevfrom
fix/studyTime
Apr 14, 2026
Merged

chore : 최대 집중시간 3시간 설정#87
Juhye0k merged 1 commit intodevfrom
fix/studyTime

Conversation

@Juhye0k
Copy link
Copy Markdown
Contributor

@Juhye0k Juhye0k commented Apr 14, 2026

🚀 1. 개요

  • 최대 집중시간 테스트 용으로 설정했던 3분을 3시간으로 정정하였습니다.

Summary by CodeRabbit

버그 수정

  • 최대 집중 모드 세션의 시간 제한 계산을 분(minute) 단위에서 시간(hour) 단위로 정확히 변경하여 시간 추적의 정확성을 향상시켰습니다.
  • 만료된 세션을 감지하는 로직의 시간 계산 기준을 분 단위에서 시간 단위로 통일하여 더욱 일관되고 안정적인 세션 관리를 제공합니다.

테스트

  • 최대 집중 세션의 시간 계산과 만료 처리 로직에 대한 테스트 범위를 확대하였습니다.

@Juhye0k Juhye0k requested review from kon28289 and removed request for kon28289 April 14, 2026 07:55
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Walkthrough

스터디 세션의 최대 집중력 시간 단위를 분(minutes)에서 시간(hours)으로 변경했습니다. StudySessionendMaxFocusStudySession 메서드와 StudySessionServiceendExpiredMaxFocusSessions 메서드에서 시간 계산 로직을 업데이트하고, 해당 동작을 검증하는 테스트를 추가했습니다.

Changes

Cohort / File(s) Summary
Domain Entity Time Unit Update
src/main/java/com/gpt/geumpumtabackend/study/domain/StudySession.java
메서드 파라미터를 maxFocusTime에서 maxFocusHours로 변경하고, plusMinutes()plusHours()로 수정하여 시간 단위 계산으로 변경했습니다.
Service Logic Time Unit Update
src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java
만료된 세션 조회 시 시간 계산을 minusMinutes()에서 minusHours()로 변경하여 일관성 있는 시간 단위 기준으로 통일했습니다.
Test Coverage Addition
src/test/java/com/gpt/geumpumtabackend/unit/study/service/StudySessionServiceTest.java
최대 집중력 세션 기능에 대한 새로운 테스트 클래스(MaxFocusCalculation)를 추가하여 시간 기반 계산과 세션 만료 로직을 검증합니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • kon28289

Poem

🐰 시간은 흐르고 분은 가고,
호랑이처럼 집중하는 시간을 재네요.
한 시간, 두 시간, 세 시간이면,
충분히 꾸준하게 공부하는 것!
단위를 바꿔도 노력은 변하지 않으니까요. ⏰✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR 설명은 필수 템플릿의 '개요' 섹션만 작성했으며, '주요 변경 사항'과 '스크린샷' 섹션이 누락되어 있습니다. '주요 변경 사항'과 '스크린샷' 섹션을 추가하여 코드 변경사항과 테스트 결과를 더 자세히 설명해 주세요.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 최대 집중시간을 3시간으로 설정하는 변경사항을 명확하게 설명하고 있으며, 변경사항의 핵심을 잘 반영하고 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/studyTime

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java (1)

107-111: ⚠️ Potential issue | 🟠 Major

정확히 3시간 경과한 세션이 누락될 수 있습니다.

Line 109의 findAllByStatusAndStartTimeBefore< 비교라 cutoff와 동일한 시작 시각은 제외됩니다. 요구사항이 “3시간 이상”이면 <= 비교 메서드로 바꾸는 게 정확합니다.

제안 코드
- List<StudySession> expiredSessions = studySessionRepository.findAllByStatusAndStartTimeBefore(
+ List<StudySession> expiredSessions = studySessionRepository.findAllByStatusAndStartTimeLessThanEqual(
         StudyStatus.STARTED, cutoffTime
 );
// src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java
List<StudySession> findAllByStatusAndStartTimeLessThanEqual(StudyStatus status, LocalDateTime cutoffTime);

Based on learnings: When a user studies for 3 hours or more, the system must automatically terminate the session.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java`
around lines 107 - 111, The current query in StudySessionService uses
studySessionRepository.findAllByStatusAndStartTimeBefore which excludes sessions
that started exactly at the cutoff (e.g., exactly 3 hours) — change the
repository method to use a less-than-or-equal variant (e.g.,
findAllByStatusAndStartTimeLessThanEqual) and update the call in
StudySessionService to use that method so sessions with startTime == cutoffTime
are included; modify the StudySessionRepository interface to declare
List<StudySession> findAllByStatusAndStartTimeLessThanEqual(StudyStatus status,
LocalDateTime cutoffTime) and replace invocations of
findAllByStatusAndStartTimeBefore in StudySessionService with the new method.
🧹 Nitpick comments (2)
src/main/java/com/gpt/geumpumtabackend/study/domain/StudySession.java (1)

50-53: maxFocusHours 입력값 검증을 추가해 종료 시점 불변식을 보호해주세요.

Line 51에서 maxFocusHours가 0 이하로 들어오면 endTime/totalMillis가 비정상 값이 될 수 있습니다. 최소 1 이상 검증을 넣는 편이 안전합니다.

제안 코드
 public void endMaxFocusStudySession(int maxFocusHours) {
+    if (maxFocusHours <= 0) {
+        throw new BusinessException(ExceptionType.INVALID_END_TIME);
+    }
     this.endTime = this.startTime.plusHours(maxFocusHours);
     status = StudyStatus.FINISHED;
     this.totalMillis = Duration.between(this.startTime, this.endTime).toMillis();
 }

Based on learnings: Validate that endTime is not earlier than startTime when ending a study session.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/gpt/geumpumtabackend/study/domain/StudySession.java` around
lines 50 - 53, The endMaxFocusStudySession method currently sets endTime and
totalMillis without validating maxFocusHours; add input validation at the start
of endMaxFocusStudySession to ensure maxFocusHours >= 1 (throw
IllegalArgumentException with a clear message if not), then compute this.endTime
= this.startTime.plusHours(maxFocusHours) and set status = StudyStatus.FINISHED;
after computing totalMillis = Duration.between(this.startTime,
this.endTime).toMillis(), also guard that totalMillis >= 0 (throw or clamp and
log if it would be negative) to ensure endTime is not earlier than startTime and
preserve invariants for endTime, startTime, and totalMillis.
src/test/java/com/gpt/geumpumtabackend/unit/study/service/StudySessionServiceTest.java (1)

317-346: 경계값(정확히 3시간) 테스트를 추가해 회귀를 막아주세요.

현재는 4시간 경과 케이스 중심이라, “정확히 3시간” 포함 여부가 깨져도 놓칠 수 있습니다. Line 318 부근에 3시간 경계 시나리오를 별도 추가하는 것을 권장합니다.

As per coding guidelines: Test coverage should include normal cases, exception cases, and boundary value cases per TESTING.md.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/com/gpt/geumpumtabackend/unit/study/service/StudySessionServiceTest.java`
around lines 317 - 346, Add a new unit test in StudySessionServiceTest that
covers the 3-hour boundary: create a User (createTestUser) and a StudySession
whose startStudySession time is LocalDateTime.now().minusHours(3), mock
studyProperties.getMaxFocusHours() to return 3 and stub
studySessionRepository.findAllByStatusAndStartTimeBefore(StudyStatus.STARTED,
...) to return that session, call
studySessionService.endExpiredMaxFocusSessions(), and assert that the repository
was called with a cutoff ~ now.minusHours(3) (capture with ArgumentCaptor), the
returned usersToNotify contains the test user, and the session’s endTime ==
start.plusHours(3), totalMillis == 10_800_000L, and status ==
StudyStatus.FINISHED; reference the existing test pattern used in
expired_cutoff_uses_three_hours and the methods endExpiredMaxFocusSessions,
studyProperties.getMaxFocusHours, and
studySessionRepository.findAllByStatusAndStartTimeBefore to implement it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java`:
- Around line 107-111: The current query in StudySessionService uses
studySessionRepository.findAllByStatusAndStartTimeBefore which excludes sessions
that started exactly at the cutoff (e.g., exactly 3 hours) — change the
repository method to use a less-than-or-equal variant (e.g.,
findAllByStatusAndStartTimeLessThanEqual) and update the call in
StudySessionService to use that method so sessions with startTime == cutoffTime
are included; modify the StudySessionRepository interface to declare
List<StudySession> findAllByStatusAndStartTimeLessThanEqual(StudyStatus status,
LocalDateTime cutoffTime) and replace invocations of
findAllByStatusAndStartTimeBefore in StudySessionService with the new method.

---

Nitpick comments:
In `@src/main/java/com/gpt/geumpumtabackend/study/domain/StudySession.java`:
- Around line 50-53: The endMaxFocusStudySession method currently sets endTime
and totalMillis without validating maxFocusHours; add input validation at the
start of endMaxFocusStudySession to ensure maxFocusHours >= 1 (throw
IllegalArgumentException with a clear message if not), then compute this.endTime
= this.startTime.plusHours(maxFocusHours) and set status = StudyStatus.FINISHED;
after computing totalMillis = Duration.between(this.startTime,
this.endTime).toMillis(), also guard that totalMillis >= 0 (throw or clamp and
log if it would be negative) to ensure endTime is not earlier than startTime and
preserve invariants for endTime, startTime, and totalMillis.

In
`@src/test/java/com/gpt/geumpumtabackend/unit/study/service/StudySessionServiceTest.java`:
- Around line 317-346: Add a new unit test in StudySessionServiceTest that
covers the 3-hour boundary: create a User (createTestUser) and a StudySession
whose startStudySession time is LocalDateTime.now().minusHours(3), mock
studyProperties.getMaxFocusHours() to return 3 and stub
studySessionRepository.findAllByStatusAndStartTimeBefore(StudyStatus.STARTED,
...) to return that session, call
studySessionService.endExpiredMaxFocusSessions(), and assert that the repository
was called with a cutoff ~ now.minusHours(3) (capture with ArgumentCaptor), the
returned usersToNotify contains the test user, and the session’s endTime ==
start.plusHours(3), totalMillis == 10_800_000L, and status ==
StudyStatus.FINISHED; reference the existing test pattern used in
expired_cutoff_uses_three_hours and the methods endExpiredMaxFocusSessions,
studyProperties.getMaxFocusHours, and
studySessionRepository.findAllByStatusAndStartTimeBefore to implement it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 57051e11-308b-487e-84d8-f7e0d244580f

📥 Commits

Reviewing files that changed from the base of the PR and between 3e3a0ac and 364dd92.

📒 Files selected for processing (3)
  • src/main/java/com/gpt/geumpumtabackend/study/domain/StudySession.java
  • src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java
  • src/test/java/com/gpt/geumpumtabackend/unit/study/service/StudySessionServiceTest.java

@Juhye0k Juhye0k merged commit aef7319 into dev Apr 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant