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 @@ -2,8 +2,11 @@

import com.ject.studytrip.pomodoro.domain.model.Pomodoro;

public record PomodoroInfo(Long pomodoroId, int focusDurationInMinute) {
public record PomodoroInfo(Long pomodoroId, int focusDurationInMinute, int focusSessionCount) {
public static PomodoroInfo from(Pomodoro pomodoro) {
return new PomodoroInfo(pomodoro.getId(), pomodoro.getFocusDurationInSeconds() / 60);
return new PomodoroInfo(
pomodoro.getId(),
pomodoro.getFocusDurationInSeconds() / 60,
pomodoro.getFocusSessionCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class PomodoroService {

public Pomodoro createPomodoro(DailyGoal dailyGoal, CreatePomodoroRequest request) {
int focusDurationInSeconds = request.focusDurationInMinute() * 60;
Pomodoro pomodoro = PomodoroFactory.create(dailyGoal, focusDurationInSeconds, 1, 0);
Pomodoro pomodoro =
PomodoroFactory.create(
dailyGoal, focusDurationInSeconds, request.focusSessionCount(), 0);
return pomodoroRepository.save(pomodoro);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class PomodoroFactory {
public static Pomodoro create(
DailyGoal dailyGoal,
int focusDurationInSeconds,
int focusCount,
int focusSessionCount,
int breakDurationInSeconds) {
return Pomodoro.of(dailyGoal, focusDurationInSeconds, focusCount, breakDurationInSeconds);
return Pomodoro.of(
dailyGoal, focusDurationInSeconds, focusSessionCount, breakDurationInSeconds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Pomodoro extends BaseTimeEntity {
private DailyGoal dailyGoal;

private int focusDurationInSeconds; // 집중 시간(초)
private int focusCount; // 집중 세션 횟수
private int focusSessionCount; // 집중 세션 횟수
private int breakDurationInSeconds; // 휴식 시간(초)
private int totalFocusTimeInSeconds; // 총 집중 시간(초)

Expand All @@ -31,12 +31,12 @@ public class Pomodoro extends BaseTimeEntity {
public static Pomodoro of(
DailyGoal dailyGoal,
int focusDurationInSeconds,
int focusCount,
int focusSessionCount,
int breakDurationInSeconds) {
return Pomodoro.builder()
.dailyGoal(dailyGoal)
.focusDurationInSeconds(focusDurationInSeconds)
.focusCount(1)
.focusSessionCount(focusSessionCount)
.breakDurationInSeconds(0)
.totalFocusTimeInSeconds(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import jakarta.validation.constraints.Min;

public record CreatePomodoroRequest(
@Min(value = 1, message = "뽀모도로 최소 집중 시간은 1분입니다.") int focusDurationInMinute) {}
@Min(value = 1, message = "뽀모도로 최소 집중 시간은 1분입니다.") int focusDurationInMinute,
@Min(value = 1, message = "뽀모도로 최소 집중 세션 개수는 1개입니다.") int focusSessionCount) {}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public static LoadDailyGoalDetailResponse of(

public record DailyGoalPomodoroResponse(
@Schema(name = "뽀모도로 ID") Long pomodoroId,
@Schema(name = "뽀모도로 집중 시간(분)") int focusDurationInMinute) {
@Schema(name = "뽀모도로 집중 시간(분)") int focusDurationInMinute,
@Schema(name = "뽀모도로 집중 세션 개수") int focusSessionCount) {
public static DailyGoalPomodoroResponse of(PomodoroInfo info) {
return new DailyGoalPomodoroResponse(info.pomodoroId(), info.focusDurationInMinute());
return new DailyGoalPomodoroResponse(
info.pomodoroId(), info.focusDurationInMinute(), info.focusSessionCount());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class createPomodoro {
@DisplayName("뽀모도로를 생성해 저장하고 반환한다")
void shouldCreateAndReturnPomodoro() {
// given
CreatePomodoroRequest request = new CreatePomodoroRequest(30);
CreatePomodoroRequest request = new CreatePomodoroRequest(30, 1);
given(pomodoroRepository.save(any())).willReturn(pomodoro);

// when
Expand All @@ -61,6 +61,7 @@ void shouldCreateAndReturnPomodoro() {
// then
assertThat(result).isNotNull();
assertThat(result.getFocusDurationInSeconds()).isEqualTo(30 * 60);
assertThat(result.getFocusSessionCount()).isEqualTo(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class CreateDailyGoalRequestFixture {

private CreatePomodoroRequest pomodoro = new CreatePomodoroRequest(30);
private CreatePomodoroRequest pomodoro = new CreatePomodoroRequest(30, 1);
private List<Long> missionIds = List.of(1L, 2L);

public CreateDailyGoalRequestFixture withPomodoro(CreatePomodoroRequest pomodoro) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.ject.studytrip.pomodoro.domain.error.PomodoroErrorCode;
import com.ject.studytrip.pomodoro.domain.model.Pomodoro;
import com.ject.studytrip.pomodoro.helper.PomodoroTestHelper;
import com.ject.studytrip.pomodoro.presentation.dto.request.CreatePomodoroRequest;
import com.ject.studytrip.stamp.domain.error.StampErrorCode;
import com.ject.studytrip.stamp.domain.model.Stamp;
import com.ject.studytrip.stamp.helper.StampTestHelper;
Expand Down Expand Up @@ -173,6 +174,50 @@ void shouldReturnBadRequestWhenInvalidRequiredFields() throws Exception {
.value()));
}

@Test
@DisplayName("데일리 목표의 뽀모도로 정보 중 집중 시간이 1분 미만이면 400 Bad Request를 반환한다")
void shouldReturnBadRequestWhenDailyGoalPomodoroFocusTimeInMinuteIsLessThanOneMinute()
throws Exception {
// given
CreateDailyGoalRequest request =
fixture.withPomodoro(new CreatePomodoroRequest(0, 1)).build();
// when
ResultActions resultActions = getResultActions(token, trip.getId(), request);

// then
resultActions
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.success").value(false))
.andExpect(
jsonPath("$.status")
.value(
CommonErrorCode.METHOD_ARGUMENT_NOT_VALID
.getStatus()
.value()));
}

@Test
@DisplayName("데일리 목표의 뽀모도로 정보 중 집중 세션이 1개 미만이면 400 Bad Request를 반환한다")
void shouldReturnBadRequestWhenDailyGoalPomodoroFocusSessionCountIsLessThanOne()
throws Exception {
// given
CreateDailyGoalRequest request =
fixture.withPomodoro(new CreatePomodoroRequest(30, 0)).build();
// when
ResultActions resultActions = getResultActions(token, trip.getId(), request);

// then
resultActions
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.success").value(false))
.andExpect(
jsonPath("$.status")
.value(
CommonErrorCode.METHOD_ARGUMENT_NOT_VALID
.getStatus()
.value()));
}

@Test
@DisplayName("유효하지 않은 여행 ID 라면 404 NotFound를 반환한다")
void shouldReturnNotFoundWhenInvalidTripId() throws Exception {
Expand Down