diff --git a/src/main/java/net/teumteum/user/domain/BalanceGameType.java b/src/main/java/net/teumteum/user/domain/BalanceGameType.java new file mode 100644 index 00000000..6c3e66fd --- /dev/null +++ b/src/main/java/net/teumteum/user/domain/BalanceGameType.java @@ -0,0 +1,34 @@ +package net.teumteum.user.domain; + +import java.util.Arrays; +import java.util.List; +import java.util.function.BiFunction; +import net.teumteum.user.domain.response.InterestQuestionResponse; + +public enum BalanceGameType { + + BALANCE("balance", (users, interestQuestion) -> interestQuestion.getBalanceGame(users)), + STORY("story", (users, interestQuestion) -> interestQuestion.getStoryGame(users)), + ; + + private final String value; + private final BiFunction, InterestQuestion, InterestQuestionResponse> behavior; + + BalanceGameType(String value, BiFunction, InterestQuestion, InterestQuestionResponse> behavior) { + this.value = value; + this.behavior = behavior; + } + + public static BalanceGameType of(String value) { + return Arrays.stream(BalanceGameType.values()) + .filter(type -> type.value.equals(value)) + .findAny() + .orElseThrow( + () -> new IllegalArgumentException("\"" + value + "\" 에 해당하는 enum값을 찾을 수 없습니다.") + ); + } + + public InterestQuestionResponse getInterestQuestionResponse(List users, InterestQuestion interestQuestion) { + return behavior.apply(users, interestQuestion); + } +} diff --git a/src/main/java/net/teumteum/user/service/UserService.java b/src/main/java/net/teumteum/user/service/UserService.java index 83b8e115..c01f8888 100644 --- a/src/main/java/net/teumteum/user/service/UserService.java +++ b/src/main/java/net/teumteum/user/service/UserService.java @@ -2,6 +2,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import net.teumteum.user.domain.BalanceGameType; import net.teumteum.user.domain.InterestQuestion; import net.teumteum.user.domain.User; import net.teumteum.user.domain.UserRepository; @@ -76,9 +77,6 @@ public InterestQuestionResponse getInterestQuestionByUserIds(List userIds, } ); - if (type.equals("balance")) { - return interestQuestion.getBalanceGame(users); - } - return interestQuestion.getStoryGame(users); + return BalanceGameType.of(type).getInterestQuestionResponse(users, interestQuestion); } }