diff --git a/src/main/java/com/alterdekim/javabot/components/StartupListener.java b/src/main/java/com/alterdekim/javabot/components/StartupListener.java index 9830460..bfd27ba 100644 --- a/src/main/java/com/alterdekim/javabot/components/StartupListener.java +++ b/src/main/java/com/alterdekim/javabot/components/StartupListener.java @@ -1,12 +1,17 @@ package com.alterdekim.javabot.components; import com.alterdekim.javabot.dto.UserDTO; +import com.alterdekim.javabot.entities.GameTheme; +import com.alterdekim.javabot.entities.TextDataVal; +import com.alterdekim.javabot.service.GameThemeService; +import com.alterdekim.javabot.service.TextDataValService; import com.alterdekim.javabot.service.UserService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; +import org.telegram.telegrambots.meta.api.objects.games.Game; import java.util.UUID; @@ -18,7 +23,15 @@ public class StartupListener { @Autowired private UserService userService; + @Autowired + private GameThemeService gameThemeService; + + @Autowired + private TextDataValService textDataValService; + + private static final String ADMIN_USERNAME = "admin"; + private static final String DEFAULT_THEME = "Default"; @EventListener public void onApplicationEvent(ContextRefreshedEvent event) { @@ -26,5 +39,12 @@ public class StartupListener { String pwd = UUID.randomUUID().toString(); log.info("Your admin account password is: {}", pwd); userService.saveUser(new UserDTO(ADMIN_USERNAME, pwd)); + gameThemeService.saveGameTheme( + new GameTheme( + textDataValService.save( + new TextDataVal(DEFAULT_THEME) + ).getId() + ) + ); } } diff --git a/src/main/java/com/alterdekim/javabot/entities/AdditionalFacts.java b/src/main/java/com/alterdekim/javabot/entities/AdditionalFacts.java index b52553e..6d3c324 100644 --- a/src/main/java/com/alterdekim/javabot/entities/AdditionalFacts.java +++ b/src/main/java/com/alterdekim/javabot/entities/AdditionalFacts.java @@ -34,4 +34,7 @@ public class AdditionalFacts { @Column(nullable = false) private Long textDescId; + + @Column(nullable = false) + private Long theme = 1L; } diff --git a/src/main/java/com/alterdekim/javabot/entities/Bio.java b/src/main/java/com/alterdekim/javabot/entities/Bio.java index 43f2807..d495553 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Bio.java +++ b/src/main/java/com/alterdekim/javabot/entities/Bio.java @@ -37,4 +37,7 @@ public class Bio { @Column(nullable = false) private Long genderTextId; + + @Column(nullable = false) + private Long theme = 1L; } diff --git a/src/main/java/com/alterdekim/javabot/entities/Disaster.java b/src/main/java/com/alterdekim/javabot/entities/Disaster.java index 3555446..13cc0ec 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Disaster.java +++ b/src/main/java/com/alterdekim/javabot/entities/Disaster.java @@ -24,6 +24,9 @@ public class Disaster { @Column(nullable = false) private Long descTextId; + @Column(nullable = false) + private Long theme = 1L; + public Disaster(Long nameTextId, Long descTextId) { this.nameTextId = nameTextId; this.descTextId = descTextId; diff --git a/src/main/java/com/alterdekim/javabot/entities/GameTheme.java b/src/main/java/com/alterdekim/javabot/entities/GameTheme.java index 3462448..07ddb85 100644 --- a/src/main/java/com/alterdekim/javabot/entities/GameTheme.java +++ b/src/main/java/com/alterdekim/javabot/entities/GameTheme.java @@ -18,6 +18,9 @@ public class GameTheme { @Column(nullable = false) private Long textNameId; + @Column(nullable = false) + private Boolean isSelected = true; + public GameTheme(Long textNameId) { this.textNameId = textNameId; } diff --git a/src/main/java/com/alterdekim/javabot/entities/Health.java b/src/main/java/com/alterdekim/javabot/entities/Health.java index b7e45b6..5bfe6cd 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Health.java +++ b/src/main/java/com/alterdekim/javabot/entities/Health.java @@ -32,6 +32,9 @@ public class Health { @Column(nullable = false) private Boolean isChildfree; + @Column(nullable = false) + private Long theme = 1L; + public Health(Float health_index, Long textNameId, Long textDescId, Boolean isChildfree) { this.health_index = health_index; this.textNameId = textNameId; diff --git a/src/main/java/com/alterdekim/javabot/entities/Hobby.java b/src/main/java/com/alterdekim/javabot/entities/Hobby.java index 015c833..eeba170 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Hobby.java +++ b/src/main/java/com/alterdekim/javabot/entities/Hobby.java @@ -41,6 +41,9 @@ public class Hobby { @Column(nullable = false) private Long textDescId; + + @Column(nullable = false) + private Long theme = 1L; public Double getValue() { return ((this.getFoodstuffs().doubleValue() + diff --git a/src/main/java/com/alterdekim/javabot/entities/Luggage.java b/src/main/java/com/alterdekim/javabot/entities/Luggage.java index c670dc3..5f90e16 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Luggage.java +++ b/src/main/java/com/alterdekim/javabot/entities/Luggage.java @@ -51,6 +51,9 @@ public class Luggage { @Column(nullable = false) private Long textDescId; + + @Column(nullable = false) + private Long theme = 1L; public Double getValue() { return ((this.getFoodstuffs().doubleValue() + diff --git a/src/main/java/com/alterdekim/javabot/entities/Synergy.java b/src/main/java/com/alterdekim/javabot/entities/Synergy.java index bd84d69..334e14f 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Synergy.java +++ b/src/main/java/com/alterdekim/javabot/entities/Synergy.java @@ -33,6 +33,9 @@ public class Synergy { @Column(nullable = false) private Float probabilityValue; + @Column(nullable = false) + private Long theme = 1L; + public Synergy(Long firstEntityId, SectionType firstType, Long secondEntityId, SectionType secondType, Float probabilityValue) { this.firstEntityId = firstEntityId; this.firstType = firstType; diff --git a/src/main/java/com/alterdekim/javabot/entities/Work.java b/src/main/java/com/alterdekim/javabot/entities/Work.java index 5559f46..3f9b6ad 100644 --- a/src/main/java/com/alterdekim/javabot/entities/Work.java +++ b/src/main/java/com/alterdekim/javabot/entities/Work.java @@ -37,6 +37,9 @@ public class Work { @Column(nullable = false) private Long textDescId; + @Column(nullable = false) + private Long theme = 1L; + public Work(Float asocial, Float power, Float violence, Float foodstuffs, Long textNameId, Long textDescId) { this.asocial = asocial; this.power = power; diff --git a/src/main/java/com/alterdekim/javabot/repository/GameThemeRepository.java b/src/main/java/com/alterdekim/javabot/repository/GameThemeRepository.java index bb5318f..d5a1961 100644 --- a/src/main/java/com/alterdekim/javabot/repository/GameThemeRepository.java +++ b/src/main/java/com/alterdekim/javabot/repository/GameThemeRepository.java @@ -2,6 +2,7 @@ package com.alterdekim.javabot.repository; import com.alterdekim.javabot.entities.GameTheme; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Optional; @@ -10,4 +11,7 @@ public interface GameThemeRepository extends JpaRepository<GameTheme, Long> { Optional<GameTheme> findById(Long id); List<GameTheme> findAll(); + + @Query("SELECT t FROM GameTheme t WHERE t.isSelected = true") + List<GameTheme> findAllSelected(); } diff --git a/src/main/java/com/alterdekim/javabot/service/GameThemeService.java b/src/main/java/com/alterdekim/javabot/service/GameThemeService.java index 735399a..2a7b525 100644 --- a/src/main/java/com/alterdekim/javabot/service/GameThemeService.java +++ b/src/main/java/com/alterdekim/javabot/service/GameThemeService.java @@ -11,4 +11,6 @@ public interface GameThemeService { void removeById(long themeId); void saveGameTheme(GameTheme gameTheme); + + List<GameTheme> getSelectedThemes(); } diff --git a/src/main/java/com/alterdekim/javabot/service/GameThemeServiceImpl.java b/src/main/java/com/alterdekim/javabot/service/GameThemeServiceImpl.java index e386632..d5dcdbb 100644 --- a/src/main/java/com/alterdekim/javabot/service/GameThemeServiceImpl.java +++ b/src/main/java/com/alterdekim/javabot/service/GameThemeServiceImpl.java @@ -32,4 +32,9 @@ public class GameThemeServiceImpl implements GameThemeService { public void saveGameTheme(GameTheme gameTheme) { repository.save(gameTheme); } + + @Override + public List<GameTheme> getSelectedThemes() { + return repository.findAllSelected(); + } }