rename StorylineHistoryRepository
This commit is contained in:
parent
2f620af594
commit
f1b1cc1afe
@ -4,7 +4,7 @@ import dev.struchkov.godfather.main.domain.StorylineHistory;
|
|||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface StorylineRepository {
|
public interface StorylineHistoryRepository {
|
||||||
|
|
||||||
Uni<Void> save(@NotNull StorylineHistory storylineHistory);
|
Uni<Void> save(@NotNull StorylineHistory storylineHistory);
|
||||||
|
|
@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface StorylineRepository {
|
public interface StorylineHistoryRepository {
|
||||||
|
|
||||||
void save(@NotNull StorylineHistory storylineHistory);
|
void save(@NotNull StorylineHistory storylineHistory);
|
||||||
|
|
@ -3,7 +3,7 @@ package dev.struchkov.godfather.quarkus.core.service;
|
|||||||
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
||||||
import dev.struchkov.godfather.main.domain.UnitPointer;
|
import dev.struchkov.godfather.main.domain.UnitPointer;
|
||||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
import dev.struchkov.godfather.quarkus.context.repository.StorylineRepository;
|
import dev.struchkov.godfather.quarkus.context.repository.StorylineHistoryRepository;
|
||||||
import dev.struchkov.godfather.quarkus.context.service.UnitPointerService;
|
import dev.struchkov.godfather.quarkus.context.service.UnitPointerService;
|
||||||
import dev.struchkov.godfather.quarkus.core.Storyline;
|
import dev.struchkov.godfather.quarkus.core.Storyline;
|
||||||
import dev.struchkov.godfather.quarkus.core.StorylineFactory;
|
import dev.struchkov.godfather.quarkus.core.StorylineFactory;
|
||||||
@ -26,24 +26,24 @@ import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
|||||||
public class StorylineMailService implements StorylineService<Mail> {
|
public class StorylineMailService implements StorylineService<Mail> {
|
||||||
|
|
||||||
private final UnitPointerService unitPointerService;
|
private final UnitPointerService unitPointerService;
|
||||||
private final StorylineRepository storylineRepository;
|
private final StorylineHistoryRepository storylineHistoryRepository;
|
||||||
private final Storyline<Mail> storyLine;
|
private final Storyline<Mail> storyLine;
|
||||||
private String defaultUnitName;
|
private String defaultUnitName;
|
||||||
|
|
||||||
public StorylineMailService(
|
public StorylineMailService(
|
||||||
UnitPointerService unitPointerService,
|
UnitPointerService unitPointerService,
|
||||||
StorylineRepository storylineRepository,
|
StorylineHistoryRepository storylineHistoryRepository,
|
||||||
List<Object> unitConfigurations
|
List<Object> unitConfigurations
|
||||||
) {
|
) {
|
||||||
this.storyLine = new StorylineFactory<Mail>(unitConfigurations).createStoryLine();
|
this.storyLine = new StorylineFactory<Mail>(unitConfigurations).createStoryLine();
|
||||||
this.unitPointerService = unitPointerService;
|
this.unitPointerService = unitPointerService;
|
||||||
this.storylineRepository = storylineRepository;
|
this.storylineHistoryRepository = storylineHistoryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uni<Void> save(@NotNull StorylineHistory storylineHistory) {
|
public Uni<Void> save(@NotNull StorylineHistory storylineHistory) {
|
||||||
isNotNull(storylineHistory);
|
isNotNull(storylineHistory);
|
||||||
return storylineRepository.save(storylineHistory);
|
return storylineHistoryRepository.save(storylineHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +69,7 @@ public class StorylineMailService implements StorylineService<Mail> {
|
|||||||
if (checkNotNull(unit) && checkNotEmpty(unit.getNextUnits())) {
|
if (checkNotNull(unit) && checkNotEmpty(unit.getNextUnits())) {
|
||||||
return Uni.createFrom().item(unit.getNextUnits());
|
return Uni.createFrom().item(unit.getNextUnits());
|
||||||
} else {
|
} else {
|
||||||
return storylineRepository.cleanHistoryByPersonId(personId)
|
return storylineHistoryRepository.cleanHistoryByPersonId(personId)
|
||||||
.onItem().transform(v -> storyLine.getStartingUnits());
|
.onItem().transform(v -> storyLine.getStartingUnits());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,18 +94,18 @@ public class StorylineMailService implements StorylineService<Mail> {
|
|||||||
storylineHistory.setPersonId(personId);
|
storylineHistory.setPersonId(personId);
|
||||||
storylineHistory.setUnitName(unitName);
|
storylineHistory.setUnitName(unitName);
|
||||||
storylineHistory.setMessage(mail);
|
storylineHistory.setMessage(mail);
|
||||||
return storylineRepository.save(storylineHistory);
|
return storylineHistoryRepository.save(storylineHistory);
|
||||||
}).replaceWithVoid();
|
}).replaceWithVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uni<StorylineHistory> replaceUserToBack(String personId, int countUnitsToBack) {
|
public Uni<StorylineHistory> replaceUserToBack(String personId, int countUnitsToBack) {
|
||||||
return storylineRepository.findByCountLast(personId, countUnitsToBack);
|
return storylineHistoryRepository.findByCountLast(personId, countUnitsToBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uni<StorylineHistory> replaceUserToBack(String personId, String unitName) {
|
public Uni<StorylineHistory> replaceUserToBack(String personId, String unitName) {
|
||||||
return storylineRepository.findByCountLast(personId, unitName);
|
return storylineHistoryRepository.findByCountLast(personId, unitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -121,7 +121,7 @@ public class StorylineMailService implements StorylineService<Mail> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uni<Void> cleanHistoryByPersonId(@NotNull String personId) {
|
public Uni<Void> cleanHistoryByPersonId(@NotNull String personId) {
|
||||||
return storylineRepository.cleanHistoryByPersonId(personId)
|
return storylineHistoryRepository.cleanHistoryByPersonId(personId)
|
||||||
.call(() -> unitPointerService.removeByPersonId(personId));
|
.call(() -> unitPointerService.removeByPersonId(personId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package dev.struchkov.godfather.simple.core.service;
|
|||||||
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
||||||
import dev.struchkov.godfather.main.domain.UnitPointer;
|
import dev.struchkov.godfather.main.domain.UnitPointer;
|
||||||
import dev.struchkov.godfather.main.domain.content.Message;
|
import dev.struchkov.godfather.main.domain.content.Message;
|
||||||
import dev.struchkov.godfather.simple.context.repository.StorylineRepository;
|
import dev.struchkov.godfather.simple.context.repository.StorylineHistoryRepository;
|
||||||
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
|
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
|
||||||
import dev.struchkov.godfather.simple.core.Storyline;
|
import dev.struchkov.godfather.simple.core.Storyline;
|
||||||
import dev.struchkov.godfather.simple.core.StorylineFactory;
|
import dev.struchkov.godfather.simple.core.StorylineFactory;
|
||||||
@ -22,24 +22,24 @@ import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
|||||||
public class StorylineMailService<T extends Message> implements StorylineService<T> {
|
public class StorylineMailService<T extends Message> implements StorylineService<T> {
|
||||||
|
|
||||||
private final UnitPointerService unitPointerService;
|
private final UnitPointerService unitPointerService;
|
||||||
private final StorylineRepository storylineRepository;
|
private final StorylineHistoryRepository storylineHistoryRepository;
|
||||||
private final Storyline<T> storyLine;
|
private final Storyline<T> storyLine;
|
||||||
private String defaultUnitName;
|
private String defaultUnitName;
|
||||||
|
|
||||||
public StorylineMailService(
|
public StorylineMailService(
|
||||||
UnitPointerService unitPointerService,
|
UnitPointerService unitPointerService,
|
||||||
StorylineRepository storylineRepository,
|
StorylineHistoryRepository storylineHistoryRepository,
|
||||||
List<Object> unitConfigurations
|
List<Object> unitConfigurations
|
||||||
) {
|
) {
|
||||||
this.storyLine = new StorylineFactory<T>(unitConfigurations).createStoryLine();
|
this.storyLine = new StorylineFactory<T>(unitConfigurations).createStoryLine();
|
||||||
this.unitPointerService = unitPointerService;
|
this.unitPointerService = unitPointerService;
|
||||||
this.storylineRepository = storylineRepository;
|
this.storylineHistoryRepository = storylineHistoryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(@NotNull StorylineHistory storylineHistory) {
|
public void save(@NotNull StorylineHistory storylineHistory) {
|
||||||
isNotNull(storylineHistory);
|
isNotNull(storylineHistory);
|
||||||
storylineRepository.save(storylineHistory);
|
storylineHistoryRepository.save(storylineHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,7 +55,7 @@ public class StorylineMailService<T extends Message> implements StorylineService
|
|||||||
.map(MainUnit::getNextUnits)
|
.map(MainUnit::getNextUnits)
|
||||||
.filter(mainUnits -> !mainUnits.isEmpty());
|
.filter(mainUnits -> !mainUnits.isEmpty());
|
||||||
if (optMainUnits.isEmpty()) {
|
if (optMainUnits.isEmpty()) {
|
||||||
storylineRepository.cleanHistoryByPersonId(personId);
|
storylineHistoryRepository.cleanHistoryByPersonId(personId);
|
||||||
}
|
}
|
||||||
final Set<MainUnit<T>> nextUnits = optMainUnits.orElse(storyLine.getStartingUnits());
|
final Set<MainUnit<T>> nextUnits = optMainUnits.orElse(storyLine.getStartingUnits());
|
||||||
nextUnits.addAll(storyLine.getGlobalUnits());
|
nextUnits.addAll(storyLine.getGlobalUnits());
|
||||||
@ -71,17 +71,17 @@ public class StorylineMailService<T extends Message> implements StorylineService
|
|||||||
storylineHistory.setPersonId(personId);
|
storylineHistory.setPersonId(personId);
|
||||||
storylineHistory.setUnitName(unitName);
|
storylineHistory.setUnitName(unitName);
|
||||||
storylineHistory.setMessage(mail);
|
storylineHistory.setMessage(mail);
|
||||||
storylineRepository.save(storylineHistory);
|
storylineHistoryRepository.save(storylineHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<StorylineHistory> replaceUserToBack(String personId, int countUnitsToBack) {
|
public Optional<StorylineHistory> replaceUserToBack(String personId, int countUnitsToBack) {
|
||||||
return storylineRepository.findByCountLast(personId, countUnitsToBack);
|
return storylineHistoryRepository.findByCountLast(personId, countUnitsToBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<StorylineHistory> replaceUserToBack(String personId, String unitName) {
|
public Optional<StorylineHistory> replaceUserToBack(String personId, String unitName) {
|
||||||
return storylineRepository.findByCountLast(personId, unitName);
|
return storylineHistoryRepository.findByCountLast(personId, unitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,7 +97,7 @@ public class StorylineMailService<T extends Message> implements StorylineService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanHistoryByPersonId(@NotNull String personId) {
|
public void cleanHistoryByPersonId(@NotNull String personId) {
|
||||||
storylineRepository.cleanHistoryByPersonId(personId);
|
storylineHistoryRepository.cleanHistoryByPersonId(personId);
|
||||||
unitPointerService.removeByPersonId(personId);
|
unitPointerService.removeByPersonId(personId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package dev.struchkov.godfather.quarkus.data.repository.impl;
|
package dev.struchkov.godfather.quarkus.data.repository.impl;
|
||||||
|
|
||||||
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
||||||
import dev.struchkov.godfather.quarkus.context.repository.StorylineRepository;
|
import dev.struchkov.godfather.quarkus.context.repository.StorylineHistoryRepository;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
public class StorylineMapRepository implements StorylineRepository {
|
public class StorylineMapHistoryRepository implements StorylineHistoryRepository {
|
||||||
|
|
||||||
private final Map<String, Stack<StorylineHistory>> map = new HashMap<>();
|
private final Map<String, Stack<StorylineHistory>> map = new HashMap<>();
|
||||||
private final Map<String, Set<String>> historyUnitName = new HashMap<>();
|
private final Map<String, Set<String>> historyUnitName = new HashMap<>();
|
@ -1,7 +1,7 @@
|
|||||||
package dev.struchkov.godfather.simple.data.repository.impl;
|
package dev.struchkov.godfather.simple.data.repository.impl;
|
||||||
|
|
||||||
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
||||||
import dev.struchkov.godfather.simple.context.repository.StorylineRepository;
|
import dev.struchkov.godfather.simple.context.repository.StorylineHistoryRepository;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -11,7 +11,7 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
public class StorylineMapRepository implements StorylineRepository {
|
public class StorylineMapHistoryRepository implements StorylineHistoryRepository {
|
||||||
|
|
||||||
private final Map<String, Stack<StorylineHistory>> map = new HashMap<>();
|
private final Map<String, Stack<StorylineHistory>> map = new HashMap<>();
|
||||||
private final Map<String, Set<String>> historyUnitName = new HashMap<>();
|
private final Map<String, Set<String>> historyUnitName = new HashMap<>();
|
Loading…
Reference in New Issue
Block a user