synergy fix

This commit is contained in:
Michael Wain 2024-11-28 00:20:15 +03:00
parent 499e3236e8
commit 99987067cc
4 changed files with 23 additions and 5 deletions

View File

@ -325,11 +325,11 @@ public class DatabaseController {
String section = params.get("section");
long entry_id = Long.parseLong(params.get("entry_id"));
switch (section) {
case "agge" -> bioService.removeById(entry_id);
case "hobb" -> hobbyService.removeById(entry_id);
case "lugg" -> luggageService.removeById(entry_id);
case "heal" -> healthService.removeById(entry_id);
case "prof" -> workService.removeById(entry_id);
case "agge" -> { bioService.removeById(entry_id); synergyService.removeByEntityId(entry_id, SectionType.AGE); }
case "hobb" -> { hobbyService.removeById(entry_id); synergyService.removeByEntityId(entry_id, SectionType.HOBBY); }
case "lugg" -> { luggageService.removeById(entry_id); synergyService.removeByEntityId(entry_id, SectionType.LUGGAGE); }
case "heal" -> { healthService.removeById(entry_id); synergyService.removeByEntityId(entry_id, SectionType.HEALTH); }
case "prof" -> { workService.removeById(entry_id); synergyService.removeByEntityId(entry_id, SectionType.WORK); }
case "actions" -> actionService.removeById(entry_id);
case "script_request" -> actionRequestService.removeById(entry_id);
case "themes" -> themeService.removeById(entry_id);

View File

@ -2,6 +2,10 @@ package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Synergy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@ -10,4 +14,9 @@ public interface SynergyRepository extends JpaRepository<Synergy, Long> {
Optional<Synergy> findById(Long id);
List<Synergy> findAll();
@Transactional
@Modifying
@Query("DELETE FROM Synergy s WHERE (s.firstEntityId = :uuid AND s.firstType = :sectionType) OR (s.secondEntityId = :uuid AND s.secondType = :sectionType)")
void deleteByEntityId(@Param("uuid") Long entityId, @Param("sectionType") Integer sectionType);
}

View File

@ -1,5 +1,6 @@
package com.alterdekim.javabot.service;
import com.alterdekim.javabot.bot.SectionType;
import com.alterdekim.javabot.entities.Luggage;
import com.alterdekim.javabot.entities.Synergy;
@ -11,4 +12,6 @@ public interface SynergyService {
void saveSynergy(Synergy synergy);
List<Synergy> getAllSynergies();
void removeByEntityId(Long entityId, SectionType sectionType);
}

View File

@ -1,5 +1,6 @@
package com.alterdekim.javabot.service;
import com.alterdekim.javabot.bot.SectionType;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.SynergyRepository;
import org.springframework.stereotype.Service;
@ -29,4 +30,9 @@ public class SynergyServiceImpl implements SynergyService {
public List<Synergy> getAllSynergies() {
return repository.findAll();
}
@Override
public void removeByEntityId(Long entityId, SectionType sectionType) {
repository.deleteByEntityId(entityId, sectionType.ordinal()+1);
}
}