Slowly adding themes x2

This commit is contained in:
Michael Wain 2024-11-27 03:16:15 +03:00
parent bb84ae88de
commit dac6c53e3f
13 changed files with 58 additions and 0 deletions

View File

@ -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()
)
);
}
}

View File

@ -34,4 +34,7 @@ public class AdditionalFacts {
@Column(nullable = false)
private Long textDescId;
@Column(nullable = false)
private Long theme = 1L;
}

View File

@ -37,4 +37,7 @@ public class Bio {
@Column(nullable = false)
private Long genderTextId;
@Column(nullable = false)
private Long theme = 1L;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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() +

View File

@ -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() +

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -11,4 +11,6 @@ public interface GameThemeService {
void removeById(long themeId);
void saveGameTheme(GameTheme gameTheme);
List<GameTheme> getSelectedThemes();
}

View File

@ -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();
}
}