Slowly adding themes x4

This commit is contained in:
Michael Wain 2024-11-27 18:26:54 +03:00
parent 8b7e89c67c
commit 5ce90afe55
11 changed files with 80 additions and 8 deletions

View File

@ -33,9 +33,6 @@ 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

@ -1,6 +1,7 @@
package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Bio;
import com.alterdekim.javabot.entities.Disaster;
import com.alterdekim.javabot.entities.Synergy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
@ -16,4 +17,7 @@ public interface BioRepository extends JpaRepository<Bio, Long> {
@Query(value = "SELECT new Synergy(s.id, s.firstEntityId, s.firstType, s.secondEntityId, s.secondType, s.probabilityValue) FROM Synergy s WHERE (s.firstType = 0 AND s.firstEntityId = :uuid) OR (s.secondType = 0 AND s.secondEntityId = :uuid)")
List<Synergy> getSynergies(@Param(value = "uuid") Long bioId);
@Query("SELECT b FROM Bio b WHERE b.theme = :th")
List<Bio> findByTheme(@Param(value = "th") Long theme);
}

View File

@ -2,6 +2,7 @@ package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Health;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.entities.Work;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@ -16,4 +17,7 @@ public interface HealthRepository extends JpaRepository<Health, Long> {
@Query(value = "SELECT new Synergy(s.id, s.firstEntityId, s.firstType, s.secondEntityId, s.secondType, s.probabilityValue) FROM Synergy s WHERE (s.firstType = 1 AND s.firstEntityId = :uuid) OR (s.secondType = 1 AND s.secondEntityId = :uuid)")
List<Synergy> getSynergies(@Param(value = "uuid") Long healthId);
@Query("SELECT h FROM Health h WHERE h.theme = :th")
List<Health> findByTheme(@Param(value = "th") Long theme);
}

View File

@ -1,5 +1,6 @@
package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Health;
import com.alterdekim.javabot.entities.Hobby;
import com.alterdekim.javabot.entities.Synergy;
import org.springframework.data.jpa.repository.JpaRepository;
@ -16,4 +17,7 @@ public interface HobbyRepository extends JpaRepository<Hobby, Long> {
@Query(value = "SELECT new Synergy(s.id, s.firstEntityId, s.firstType, s.secondEntityId, s.secondType, s.probabilityValue) FROM Synergy s WHERE (s.firstType = 2 AND s.firstEntityId = :uuid) OR (s.secondType = 2 AND s.secondEntityId = :uuid)")
List<Synergy> getSynergies(@Param(value = "uuid") Long hobbId);
@Query("SELECT h FROM Hobby h WHERE h.theme = :th")
List<Hobby> findByTheme(@Param(value = "th") Long theme);
}

View File

@ -1,5 +1,6 @@
package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Hobby;
import com.alterdekim.javabot.entities.Luggage;
import com.alterdekim.javabot.entities.Synergy;
import org.springframework.data.jpa.repository.JpaRepository;
@ -16,4 +17,7 @@ public interface LuggageRepository extends JpaRepository<Luggage, Long> {
@Query(value = "SELECT new Synergy(s.id, s.firstEntityId, s.firstType, s.secondEntityId, s.secondType, s.probabilityValue) FROM Synergy s WHERE (s.firstType = 3 AND s.firstEntityId = :uuid) OR (s.secondType = 3 AND s.secondEntityId = :uuid)")
List<Synergy> getSynergies(@Param(value = "uuid") Long luggId);
@Query("SELECT l FROM Luggage l WHERE l.theme = :th")
List<Luggage> findByTheme(@Param(value = "th") Long theme);
}

View File

@ -1,5 +1,6 @@
package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Disaster;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.entities.Work;
import org.springframework.data.jpa.repository.JpaRepository;
@ -16,4 +17,7 @@ public interface WorkRepository extends JpaRepository<Work, Long> {
@Query(value = "SELECT new Synergy(s.id, s.firstEntityId, s.firstType, s.secondEntityId, s.secondType, s.probabilityValue) FROM Synergy s WHERE (s.firstType = 4 AND s.firstEntityId = :uuid) OR (s.secondType = 4 AND s.secondEntityId = :uuid)")
List<Synergy> getSynergies(@Param(value = "uuid") Long workId);
@Query("SELECT w FROM Work w WHERE w.theme = :th")
List<Work> findByTheme(@Param(value = "th") Long theme);
}

View File

@ -3,13 +3,20 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Bio;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.BioRepository;
import com.alterdekim.javabot.repository.GameThemeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class BioServiceImpl implements BioService {
@Autowired
private GameThemeRepository themeRepository;
private BioRepository repository;
public BioServiceImpl(BioRepository repository) {
@ -18,7 +25,11 @@ public class BioServiceImpl implements BioService {
@Override
public List<Bio> getAllBios() {
return repository.findAll();
return themeRepository.findAllSelected()
.stream()
.map(t -> repository.findByTheme(t.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override

View File

@ -2,14 +2,21 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Health;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.GameThemeRepository;
import com.alterdekim.javabot.repository.HealthRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class HealthServiceImpl implements HealthService {
@Autowired
private GameThemeRepository themeRepository;
private final HealthRepository repository;
public HealthServiceImpl(HealthRepository repository) {
@ -18,7 +25,11 @@ public class HealthServiceImpl implements HealthService {
@Override
public List<Health> getAllHealth() {
return repository.findAll();
return themeRepository.findAllSelected()
.stream()
.map(t -> repository.findByTheme(t.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override

View File

@ -2,14 +2,21 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Hobby;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.GameThemeRepository;
import com.alterdekim.javabot.repository.HobbyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class HobbyServiceImpl implements HobbyService {
@Autowired
private GameThemeRepository themeRepository;
private final HobbyRepository repository;
public HobbyServiceImpl(HobbyRepository repository) {
@ -18,7 +25,11 @@ public class HobbyServiceImpl implements HobbyService {
@Override
public List<Hobby> getAllHobbies() {
return repository.findAll();
return themeRepository.findAllSelected()
.stream()
.map(t -> repository.findByTheme(t.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override

View File

@ -2,21 +2,32 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Luggage;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.GameThemeRepository;
import com.alterdekim.javabot.repository.LuggageRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@AllArgsConstructor
@Service
public class LuggageServiceImpl implements LuggageService {
@Autowired
private GameThemeRepository themeRepository;
private final LuggageRepository repository;
@Override
public List<Luggage> getAllLuggages() {
return repository.findAll();
return themeRepository.findAllSelected()
.stream()
.map(t -> repository.findByTheme(t.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override

View File

@ -2,14 +2,21 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.entities.Work;
import com.alterdekim.javabot.repository.GameThemeRepository;
import com.alterdekim.javabot.repository.WorkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class WorkServiceImpl implements WorkService {
@Autowired
private GameThemeRepository themeRepository;
private final WorkRepository repository;
public WorkServiceImpl(WorkRepository repository) {
@ -18,7 +25,11 @@ public class WorkServiceImpl implements WorkService {
@Override
public List<Work> getAllWorks() {
return repository.findAll();
return themeRepository.findAllSelected()
.stream()
.map(t -> repository.findByTheme(t.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override