-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
클라이언트에서 싱글모드 정지, 실행 기능이 추가되면서 runningTIme을 저장해야했습니다. 따라서 single 엔티티에 runningTime을 추가했습니다. 직전의 직렬화 이슈 말고는 크게 다룰 내용은 없습니다.
- Loading branch information
1 parent
a5fa53e
commit e9e206a
Showing
10 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...main/java/online/partyrun/partyrunbattleservice/domain/single/dto/RunningTimeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package online.partyrun.partyrunbattleservice.domain.single.dto; | ||
|
||
import online.partyrun.partyrunbattleservice.domain.single.entity.RunningTime; | ||
|
||
public record RunningTimeRequest(int hours, int minutes, int seconds) { | ||
|
||
public RunningTime toRunningTime() { | ||
return new RunningTime(hours, minutes, seconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/online/partyrun/partyrunbattleservice/domain/single/entity/RunningTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package online.partyrun.partyrunbattleservice.domain.single.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import online.partyrun.partyrunbattleservice.domain.single.exception.IllegalRunningTimeException; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
public class RunningTime { | ||
|
||
private static final int MIN_TIME = 0; | ||
private static final int MAX_TIME = 59; | ||
|
||
int hours; | ||
int minutes; | ||
int seconds; | ||
|
||
public RunningTime(int hours, int minutes, int seconds) { | ||
validateNoTime(hours, minutes, seconds); | ||
validateIsCorrectTime(hours, minutes, seconds); | ||
|
||
|
||
this.hours = hours; | ||
this.minutes = minutes; | ||
this.seconds = seconds; | ||
} | ||
|
||
private void validateNoTime(int hours, int minutes, int seconds) { | ||
if (hours == MIN_TIME && minutes == MIN_TIME && seconds == MIN_TIME) { | ||
throw new IllegalRunningTimeException(hours, minutes, seconds); | ||
} | ||
} | ||
|
||
private void validateIsCorrectTime(int hours, int minutes, int seconds) { | ||
if (isNotCorrectHours(hours) || isNotCorrectMinutes(minutes) || isNotCorrectSeconds(seconds)) { | ||
throw new IllegalRunningTimeException(hours, minutes, seconds); | ||
} | ||
} | ||
|
||
private boolean isNotCorrectHours(int hours) { | ||
return MIN_TIME > hours; | ||
} | ||
|
||
private boolean isNotCorrectMinutes(int minutes) { | ||
return minutes < MIN_TIME || minutes > MAX_TIME; | ||
} | ||
|
||
private boolean isNotCorrectSeconds(int seconds) { | ||
return seconds < MIN_TIME || seconds > MAX_TIME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...e/partyrun/partyrunbattleservice/domain/single/exception/IllegalRunningTimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package online.partyrun.partyrunbattleservice.domain.single.exception; | ||
|
||
import online.partyrun.partyrunbattleservice.global.exception.BadRequestException; | ||
|
||
public class IllegalRunningTimeException extends BadRequestException { | ||
|
||
public IllegalRunningTimeException(int hours, int minutes, int seconds) { | ||
super(String.format("RunningTime은 %d시 %d분 %d초 일 수 없습니다.", hours, minutes, seconds)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...test/java/online/partyrun/partyrunbattleservice/domain/single/entity/RunningTimeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package online.partyrun.partyrunbattleservice.domain.single.entity; | ||
|
||
import online.partyrun.partyrunbattleservice.domain.single.exception.IllegalRunningTimeException; | ||
import org.junit.jupiter.api.*; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@DisplayName("RunningTime") | ||
class RunningTimeTest { | ||
|
||
@Nested | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
class RunningTime을_생성할_때 { | ||
|
||
@ParameterizedTest | ||
@DisplayName("잘못된 시간이 들어오면 예외를 던진다.") | ||
@CsvSource(value = {"-1,1,1", "1,-1,1", "1,60,1", "1,59,-1", "1,59,60","0,0,0"}) | ||
void throwExceptionForCorrectTime(int hours, int minutes, int seconds) { | ||
assertThatThrownBy(() -> new RunningTime(hours, minutes, seconds)) | ||
.isInstanceOf(IllegalRunningTimeException.class); | ||
} | ||
|
||
@ParameterizedTest | ||
@DisplayName("올바른 시간이 들어오면 RunningTime을 생성한다.") | ||
@CsvSource(value = {"0,0,1", "0,1,0", "1,0,0"}) | ||
void create(int hours, int minutes, int seconds) { | ||
assertThatCode(() -> new RunningTime(hours, minutes, seconds)) | ||
.doesNotThrowAnyException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters