-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 방 설정 변경에 검증 로직 추가 #219
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be5fee4
feat: 방 설정 변경에 검증 로직 추가 #215
PgmJun c9d23a6
fix: getRoom 메서드 트랜잭션 readOnly true로 변경 #215
PgmJun a776980
fix: RoomSetting 기본생성자 접근제어 Package-Private로 변경 #215
PgmJun c414ce3
fix: 테스트를 위한 코드 제거 #215
PgmJun 62cf823
test: RoomSetting 테스트와 RoomTest 분리 #215
PgmJun 6561b1b
merge: develop 변경 사항 반영 #215
PgmJun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
63 changes: 62 additions & 1 deletion
63
backend/src/main/java/ddangkong/domain/room/RoomSetting.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 |
---|---|---|
@@ -1,21 +1,82 @@ | ||
package ddangkong.domain.room; | ||
|
||
import ddangkong.domain.balance.content.Category; | ||
import ddangkong.exception.BadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
// todo embeddable | ||
@Embeddable | ||
@EqualsAndHashCode | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class RoomSetting { | ||
|
||
private static final int DEFAULT_TOTAL_ROUND = 5; | ||
private static final int MIN_TOTAL_ROUND = 3; | ||
private static final int MAX_TOTAL_ROUND = 10; | ||
private static final List<Integer> ALLOWED_TIME_LIMIT = List.of(5_000, 10_000, 15_000); | ||
private static final int DEFAULT_TIME_LIMIT_MSEC = 10_000; | ||
|
||
@Column(nullable = false) | ||
private int totalRound; | ||
|
||
@Column(nullable = false) | ||
private int timeLimit; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private Category category; | ||
|
||
public static RoomSetting createNewRoomSetting() { | ||
return new RoomSetting(DEFAULT_TOTAL_ROUND, DEFAULT_TIME_LIMIT_MSEC, Category.IF); | ||
} | ||
|
||
public RoomSetting(int totalRound, int timeLimit, Category category) { | ||
validateTotalRound(totalRound); | ||
validateTimeLimit(timeLimit); | ||
|
||
this.totalRound = totalRound; | ||
this.timeLimit = timeLimit; | ||
this.category = category; | ||
} | ||
|
||
private void validateTotalRound(int totalRound) { | ||
if (totalRound < MIN_TOTAL_ROUND || totalRound > MAX_TOTAL_ROUND) { | ||
throw new BadRequestException("총 라운드는 %d 이상, %d 이하만 가능합니다. requested totalRound: %d" | ||
.formatted(MIN_TOTAL_ROUND, MAX_TOTAL_ROUND, totalRound)); | ||
} | ||
} | ||
|
||
private void validateTimeLimit(int timeLimit) { | ||
if (!ALLOWED_TIME_LIMIT.contains(timeLimit)) { | ||
throw new BadRequestException("시간 제한은 %dms / %dms / %dms 만 가능합니다. requested timeLimit: %d" | ||
.formatted(ALLOWED_TIME_LIMIT.get(0), ALLOWED_TIME_LIMIT.get(1), ALLOWED_TIME_LIMIT.get(2), | ||
timeLimit)); | ||
} | ||
} | ||
|
||
public void updateTotalRound(int totalRound) { | ||
validateTotalRound(totalRound); | ||
this.totalRound = totalRound; | ||
} | ||
|
||
public void updateTimeLimit(int timeLimit) { | ||
validateTimeLimit(timeLimit); | ||
this.timeLimit = timeLimit; | ||
} | ||
|
||
public void updateCategory(Category category) { | ||
this.category = category; | ||
} | ||
|
||
public boolean isFinalRound(int currentRound) { | ||
return totalRound == currentRound; | ||
} | ||
} |
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
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
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
backend/src/test/java/ddangkong/domain/room/RoomSettingTest.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 ddangkong.domain.room; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import ddangkong.domain.balance.content.Category; | ||
import ddangkong.exception.BadRequestException; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class RoomSettingTest { | ||
@Nested | ||
class 방_설정_변경 { | ||
@ParameterizedTest | ||
@ValueSource(ints = {2, 11}) | ||
void 라운드는_3이상_10이하_여야한다(int notValidTotalRound) { | ||
// when & then | ||
assertThatThrownBy(() -> new RoomSetting(notValidTotalRound, 5000, Category.IF)) | ||
.isExactlyInstanceOf(BadRequestException.class) | ||
.hasMessage("총 라운드는 %d 이상, %d 이하만 가능합니다. requested totalRound: %d" | ||
.formatted(3, 10, notValidTotalRound)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {5001, 10001, 15001}) | ||
void 시간_제한은_5000_10000_15000중_하나_여야한다(int notValidTimeLimit) { | ||
// when & then | ||
assertThatThrownBy(() -> new RoomSetting(5, notValidTimeLimit, Category.IF)) | ||
.isExactlyInstanceOf(BadRequestException.class) | ||
.hasMessage("시간 제한은 %dms / %dms / %dms 만 가능합니다. requested timeLimit: %d" | ||
.formatted(5000, 10000, 15000, notValidTimeLimit)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사해용 ~