Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.gpt.geumpumtabackend.study.dto.response;

public record StudySessionResponse(Long totalStudySession, boolean isStudying) {
import java.time.LocalDateTime;

public static StudySessionResponse of(Long totalStudySession, boolean isStudying) {
return new StudySessionResponse(totalStudySession, isStudying);
public record StudySessionResponse(Long totalStudySession, boolean isStudying, LocalDateTime startTime) {

public static StudySessionResponse of(Long totalStudySession, boolean isStudying, LocalDateTime startTime) {
return new StudySessionResponse(totalStudySession, isStudying, startTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public class StudySessionService {
public StudySessionResponse getTodayStudySession(Long userId) {
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
LocalDateTime now = LocalDateTime.now();
boolean isStudying = studySessionRepository.findByUser_IdAndStatus(userId, StudyStatus.STARTED).isPresent();
StudySession activeSession = studySessionRepository.findByUser_IdAndStatus(userId, StudyStatus.STARTED)
.orElse(null);
boolean isStudying = activeSession != null;
LocalDateTime startTime = isStudying ? activeSession.getStartTime() : null;
Long totalStudySession = studySessionRepository.sumCompletedStudySessionByUserId(userId, startOfDay, now);
return StudySessionResponse.of(totalStudySession,isStudying);
return StudySessionResponse.of(totalStudySession, isStudying, startTime);
}
Comment on lines 41 to 50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

조회 메서드 트랜잭션 설정이 빠져 있습니다.

getTodayStudySession는 읽기 전용 로직이므로 readOnly 트랜잭션 정책을 적용해 주세요. 현재 클래스/메서드 기준으로 조회 기본 정책이 명시되지 않았습니다.

🔧 제안 수정안
 `@Service`
 `@RequiredArgsConstructor`
 `@Slf4j`
+@Transactional(readOnly = true)
 public class StudySessionService {
@@
-    public StudySessionResponse getTodayStudySession(Long userId) {
+    public StudySessionResponse getTodayStudySession(Long userId) {
         LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
         LocalDateTime now = LocalDateTime.now();
         StudySession activeSession = studySessionRepository.findByUser_IdAndStatus(userId, StudyStatus.STARTED)
                 .orElse(null);

As per coding guidelines "src/main/java/com/gpt/geumpumtabackend//service//*.java: Apply @Transactional appropriately, using readOnly = true for read-only operations" and "**/*Service.java: Use class-level @Transactional(readOnly = true) and add @Transactional to write methods".

🤖 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 41 - 50, The getTodayStudySession method in StudySessionService is
missing a read-only transaction: add transactional semantics by annotating the
StudySessionService class with `@Transactional`(readOnly = true) (importing
org.springframework.transaction.annotation.Transactional) and then explicitly
annotate any mutating service methods (e.g., create/update/delete methods in
StudySessionService) with `@Transactional` (without readOnly) so writes are
handled correctly; alternatively, if you prefer method-level scope, annotate
getTodayStudySession with `@Transactional`(readOnly = true) instead of
class-level.


/*
Expand Down
Loading