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
Expand Up @@ -40,8 +40,8 @@ public Pomodoro getValidPomodoroByDailyGoal(Long dailyGoalId) {
return pomodoro;
}

public void updateTotalFocusTime(Long dailyGoalId, int totalFocusTimeInMinutes) {
PomodoroPolicy.validateTotalFocusTimeNotNegative(totalFocusTimeInMinutes);
public void updateTotalFocusTime(Long dailyGoalId, int totalFocusTimeInSeconds) {
PomodoroPolicy.validateTotalFocusTimeNotNegative(totalFocusTimeInSeconds);

Pomodoro pomodoro =
pomodoroRepository
Expand All @@ -50,7 +50,6 @@ public void updateTotalFocusTime(Long dailyGoalId, int totalFocusTimeInMinutes)
() -> new CustomException(PomodoroErrorCode.POMODORO_NOT_FOUND));
PomodoroPolicy.validateNotDeleted(pomodoro);

int totalFocusTimeInSeconds = totalFocusTimeInMinutes * 60;
pomodoro.updateTotalFocusTimeInSeconds(totalFocusTimeInSeconds);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.ject.studytrip.pomodoro.presentation.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;

public record CreatePomodoroRequest(
@Min(value = 1, message = "뽀모도로 최소 집중 시간은 1분입니다.") int focusDurationInMinute,
@Min(value = 1, message = "뽀모도로 최소 집중 세션 개수는 1개입니다.") int focusSessionCount) {}
@Schema(description = "집중 시간(분)") @Min(value = 1, message = "뽀모도로 최소 집중 시간은 1분입니다.")
int focusDurationInMinute,
@Schema(description = "집중 세션 개수") @Min(value = 1, message = "뽀모도로 최소 집중 세션 개수는 1개입니다.")
int focusSessionCount) {}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public StudyLogInfo createStudyLog(
studyLogService.createStudyLog(trip.getMember(), dailyGoal, request.content());

// 3. 뽀모도로 총 학습시간 업데이트
pomodoroService.updateTotalFocusTime(dailyGoalId, request.totalFocusTimeInMinutes());
pomodoroService.updateTotalFocusTime(dailyGoalId, request.totalFocusTimeInSeconds());

// 4. 연관 데이터 생성 및 미션 완료 처리
createStudyLogDailyMissionsAndCompleteMissions(studyLog, selectedDailyMissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.List;

public record CreateStudyLogRequest(
@Schema(description = "뽀모도로 총 집중시간()") @Min(value = 0, message = "총 집중시간()은 음수일 수 없습니다.")
int totalFocusTimeInMinutes,
@Schema(description = "뽀모도로 총 집중시간()") @Min(value = 0, message = "총 집중시간()은 음수일 수 없습니다.")
int totalFocusTimeInSeconds,
@Schema(description = "선택한 데일리 미션 ID 목록")
@NotEmpty(message = "학습로그를 작성할 데일리 미션 목록은 필수 요청 값입니다.")
List<Long> selectedDailyMissionIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,28 @@ class UpdateTotalFocusTime {
@DisplayName("유효한 데일리 목표 ID와 총 학습시간으로 뽀모도로의 총 학습시간을 업데이트한다")
void shouldUpdateTotalFocusTime() {
// given
int totalFocusTimeInMinutes = 120;
int totalFocusTimeInSeconds = 120;
given(pomodoroRepository.findByDailyGoalId(dailyGoal.getId()))
.willReturn(Optional.of(pomodoro));

// when
pomodoroService.updateTotalFocusTime(dailyGoal.getId(), totalFocusTimeInMinutes);
pomodoroService.updateTotalFocusTime(dailyGoal.getId(), totalFocusTimeInSeconds);

// then
assertThat(pomodoro.getTotalFocusTimeInSeconds())
.isEqualTo(totalFocusTimeInMinutes * 60);
assertThat(pomodoro.getTotalFocusTimeInSeconds()).isEqualTo(totalFocusTimeInSeconds);
}

@Test
@DisplayName("뽀모도로 총 집중시간(분)이 음수일 경우 예외가 발생한다")
void shouldThrowExceptionWhenTotalFocusTimeIsNegative() {
// given
int totalFocusTimeInMinutes = -30;
int totalFocusTimeInSeconds = -30;

// when & then
assertThatThrownBy(
() ->
pomodoroService.updateTotalFocusTime(
dailyGoal.getId(), totalFocusTimeInMinutes))
dailyGoal.getId(), totalFocusTimeInSeconds))
.isInstanceOf(CustomException.class)
.hasMessage(PomodoroErrorCode.POMODORO_NEGATIVE_FOCUS_TIME.getMessage());
}
Expand All @@ -166,15 +165,15 @@ void shouldThrowExceptionWhenTotalFocusTimeIsNegative() {
@DisplayName("뽀모도로가 존재하지 않으면 예외가 발생한다")
void shouldThrowExceptionWhenPomodoroNotFound() {
// given
int totalFocusTimeInMinutes = 60;
int totalFocusTimeInSeconds = 60;
given(pomodoroRepository.findByDailyGoalId(dailyGoal.getId()))
.willReturn(Optional.empty());

// when & then
assertThatThrownBy(
() ->
pomodoroService.updateTotalFocusTime(
dailyGoal.getId(), totalFocusTimeInMinutes))
dailyGoal.getId(), totalFocusTimeInSeconds))
.isInstanceOf(CustomException.class)
.hasMessage(PomodoroErrorCode.POMODORO_NOT_FOUND.getMessage());
}
Expand All @@ -183,7 +182,7 @@ void shouldThrowExceptionWhenPomodoroNotFound() {
@DisplayName("삭제된 뽀모도로일 경우 예외가 발생한다")
void shouldThrowExceptionWhenPomodoroIsDeleted() {
// given
int totalFocusTimeInMinutes = 60;
int totalFocusTimeInSeconds = 60;
pomodoro.updateDeletedAt();
given(pomodoroRepository.findByDailyGoalId(dailyGoal.getId()))
.willReturn(Optional.of(pomodoro));
Expand All @@ -192,7 +191,7 @@ void shouldThrowExceptionWhenPomodoroIsDeleted() {
assertThatThrownBy(
() ->
pomodoroService.updateTotalFocusTime(
dailyGoal.getId(), totalFocusTimeInMinutes))
dailyGoal.getId(), totalFocusTimeInSeconds))
.isInstanceOf(CustomException.class)
.hasMessage(PomodoroErrorCode.POMODORO_ALREADY_DELETED.getMessage());
}
Expand Down