diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/AvatarSpeechProvider.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/AvatarSpeechProvider.java index 301b3cb3..45bf7c45 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/AvatarSpeechProvider.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/AvatarSpeechProvider.java @@ -1,6 +1,6 @@ package com.wakeUpTogetUp.togetUp.api.avatar.application; -import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.SpeechStrategy; +import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.MakeSpeechStrategy; import com.wakeUpTogetUp.togetUp.api.avatar.domain.Avatar; import com.wakeUpTogetUp.togetUp.api.avatar.domain.AvatarSpeech; import com.wakeUpTogetUp.togetUp.api.avatar.domain.AvatarSpeechCondition; @@ -30,28 +30,31 @@ public class AvatarSpeechProvider { private final AvatarRepository avatarRepository; private final AvatarSpeechRepository avatarSpeechRepository; - private final SpeechStrategyFactory speechStrategyFactory; + private final MakeSpeechStrategyFactory makeSpeechStrategyFactory; private final Random random = new Random(); public AvatarSpeechResponse getUserAvatarSpeech(int userId, int avatarId) { userAvatarValidationService.validateUserAvatarActive(userId, avatarId); - String speech = makeSpeechByCondition(getSpeechByAvatar(avatarId)); + String speech = makeSpeechByCondition(selectSpeechByAvatar(avatarId)); return EntityDtoMapper.INSTANCE.toAvatarSpeechResponse(speech); } private String makeSpeechByCondition(AvatarSpeech avatarSpeech) { - SpeechStrategy strategy = speechStrategyFactory.getStrategy(avatarSpeech.getCondition()); + MakeSpeechStrategy strategy = makeSpeechStrategyFactory.getStrategy(avatarSpeech.getCondition()); return strategy.makeSpeech(avatarSpeech); } - private AvatarSpeech getSpeechByAvatar(int avatarId) { + private AvatarSpeech selectSpeechByAvatar(int avatarId) { Avatar avatar = avatarRepository.findById(avatarId) .orElseThrow(() -> new BaseException(Status.AVATAR_NOT_FOUND)); - AvatarTheme avatarTheme = AvatarTheme.valueOf(avatar.getTheme()); - switch (avatarTheme) { + if (!AvatarTheme.isExist(avatar.getTheme())) { + return getRandomOneByAvatar(avatarId); + } + + switch (AvatarTheme.valueOf(avatar.getTheme())) { case ASTRONAUT_BEAR: LocalDate today = LocalDate.now(); return getByAvatarAndLunarCondition(avatarId, today); diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/SpeechStrategyFactory.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/MakeSpeechStrategyFactory.java similarity index 60% rename from src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/SpeechStrategyFactory.java rename to src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/MakeSpeechStrategyFactory.java index 5373a5bd..ca43313a 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/SpeechStrategyFactory.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/MakeSpeechStrategyFactory.java @@ -1,9 +1,9 @@ package com.wakeUpTogetUp.togetUp.api.avatar.application; -import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.BasicSpeechStrategy; -import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.FoodSpeechStrategy; -import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.SpeechStrategy; -import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.TimeSpeechStrategy; +import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.BasicMakeSpeechStrategy; +import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.FoodMakeSpeechStrategy; +import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.MakeSpeechStrategy; +import com.wakeUpTogetUp.togetUp.api.avatar.application.strategy.TimeMakeSpeechStrategy; import com.wakeUpTogetUp.togetUp.api.avatar.domain.AvatarSpeechCondition; import java.util.EnumMap; import java.util.Map; @@ -13,11 +13,11 @@ @Component @RequiredArgsConstructor -public class SpeechStrategyFactory { - private static final Map strategies = new EnumMap<>(AvatarSpeechCondition.class); - private final BasicSpeechStrategy basicSpeechStrategy; - private final FoodSpeechStrategy foodSpeechStrategy; - private final TimeSpeechStrategy timeSpeechStrategy; +public class MakeSpeechStrategyFactory { + private static final Map strategies = new EnumMap<>(AvatarSpeechCondition.class); + private final BasicMakeSpeechStrategy basicSpeechStrategy; + private final FoodMakeSpeechStrategy foodSpeechStrategy; + private final TimeMakeSpeechStrategy timeSpeechStrategy; @PostConstruct public void init() { @@ -27,7 +27,7 @@ public void init() { strategies.put(AvatarSpeechCondition.TIME, timeSpeechStrategy); } - public SpeechStrategy getStrategy(AvatarSpeechCondition condition) { - return strategies.getOrDefault(condition, new BasicSpeechStrategy()); + public MakeSpeechStrategy getStrategy(AvatarSpeechCondition condition) { + return strategies.getOrDefault(condition, new BasicMakeSpeechStrategy()); } } diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicSpeechStrategy.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicMakeSpeechStrategy.java similarity index 82% rename from src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicSpeechStrategy.java rename to src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicMakeSpeechStrategy.java index b276df93..bdae0340 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicSpeechStrategy.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/BasicMakeSpeechStrategy.java @@ -4,7 +4,7 @@ import org.springframework.stereotype.Component; @Component -public class BasicSpeechStrategy implements SpeechStrategy{ +public class BasicMakeSpeechStrategy implements MakeSpeechStrategy { @Override public String makeSpeech(AvatarSpeech avatarSpeech) { diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodSpeechStrategy.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodMakeSpeechStrategy.java similarity index 89% rename from src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodSpeechStrategy.java rename to src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodMakeSpeechStrategy.java index f7150a2e..96a0a8c7 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodSpeechStrategy.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/FoodMakeSpeechStrategy.java @@ -7,7 +7,7 @@ @Component @RequiredArgsConstructor -public class FoodSpeechStrategy implements SpeechStrategy{ +public class FoodMakeSpeechStrategy implements MakeSpeechStrategy { private final RandomFoodProvider randomFoodProvider; diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/SpeechStrategy.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/MakeSpeechStrategy.java similarity index 83% rename from src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/SpeechStrategy.java rename to src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/MakeSpeechStrategy.java index 1a8d7340..438465f4 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/SpeechStrategy.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/MakeSpeechStrategy.java @@ -2,7 +2,7 @@ import com.wakeUpTogetUp.togetUp.api.avatar.domain.AvatarSpeech; -public interface SpeechStrategy { +public interface MakeSpeechStrategy { String makeSpeech(AvatarSpeech avatarSpeech); } diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeSpeechStrategy.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeMakeSpeechStrategy.java similarity index 88% rename from src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeSpeechStrategy.java rename to src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeMakeSpeechStrategy.java index 17b69661..dfee3bde 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeSpeechStrategy.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/application/strategy/TimeMakeSpeechStrategy.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component; @Component -public class TimeSpeechStrategy implements SpeechStrategy{ +public class TimeMakeSpeechStrategy implements MakeSpeechStrategy { @Override public String makeSpeech(AvatarSpeech avatarSpeech) { diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/domain/AvatarTheme.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/domain/AvatarTheme.java index 945574b1..c6eeff6c 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/domain/AvatarTheme.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/avatar/domain/AvatarTheme.java @@ -1,5 +1,6 @@ package com.wakeUpTogetUp.togetUp.api.avatar.domain; +import java.util.Arrays; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -8,5 +9,11 @@ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum AvatarTheme { - ASTRONAUT_BEAR, + ASTRONAUT_BEAR + ; + + public static boolean isExist(String name) { + return Arrays.stream(values()) + .anyMatch(v -> v.name().equals(name)); + } }