use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method modifySignUp.
public Raid modifySignUp(String raidId, User user, int mystic, int instinct, int valor, int plebs, LocalDateTime startAt) {
RaidEntity raidEntity = findEntityByRaidId(raidId);
RaidEntitySignUp signUp = raidEntity.getSignUp(user.getName());
final String startAtTime = Utils.printTime(startAt.toLocalTime());
if (signUp == null) {
final int sum = mystic + instinct + valor + plebs;
assertSumNotLessThanOne(user, sum);
raidEntity.addSignUp(new RaidEntitySignUp(user.getName(), sum, startAtTime));
} else {
int sum = signUp.getNumberOfPeople();
if (startAt.toLocalTime().equals(Utils.parseTime(user, signUp.getEta(), localeService))) {
sum = sum + mystic + instinct + valor + plebs;
} else {
signUp.setEta(startAtTime);
// Reset number of signups to what the input gives since we changed time
sum = mystic + instinct + valor + plebs;
}
assertSumNotLessThanOne(user, sum);
signUp.setNumberOfPeople(sum, localeService, user);
}
raidEntity = raidEntityRepository.save(raidEntity);
return getRaidInstance(raidEntity);
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method changeGroup.
public RaidGroup changeGroup(User user, String raidId, String groupCreatorId, LocalDateTime currentStartAt, LocalDateTime newDateTime) {
final RaidEntity entityByRaidId = findEntityByRaidId(raidId);
if (entityByRaidId == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
RaidGroup group = entityByRaidId.getGroupByCreatorAndStart(groupCreatorId, currentStartAt);
if (group == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SUCH_GROUP, localeService.getLocaleForUser(user)));
}
group.setStartsAt(newDateTime);
raidEntityRepository.save(entityByRaidId);
return group;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method moveAllSignUpsForTimeToNewTime.
public void moveAllSignUpsForTimeToNewTime(String raidId, LocalDateTime currentStartAt, LocalDateTime newDateTime, User user) {
Validate.notNull(raidId, "Raid ID cannot be null");
Validate.notNull(currentStartAt, "Current start time cannot be null");
Validate.notNull(newDateTime, "New start time cannot be null");
Validate.notNull(user, "User cannot be null");
RaidEntity entity = raidEntityRepository.findOne(raidId);
if (entity != null) {
for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
if (signUp.getArrivalTime().equals(currentStartAt.toLocalTime())) {
signUp.setEta(Utils.printTime(newDateTime.toLocalTime()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Changed ETA for signup: " + signUp);
}
}
}
raidEntityRepository.save(entity);
} else {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method findEntityByRaidId.
private RaidEntity findEntityByRaidId(String raidId) {
final RaidEntity raidEntity = raidId == null ? null : raidEntityRepository.findOne(raidId);
removeRaidIfExpired(raidEntity);
return raidEntity;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getRaidsInRegionForPokemon.
public Set<Raid> getRaidsInRegionForPokemon(String region, Pokemon pokemon) {
removeExpiredRaids(region);
List<RaidEntity> raidEntityList = raidEntityRepository.findByPokemonAndRegionOrderByEndOfRaidAsc(pokemon.getName(), region);
Set<Raid> activeRaids = new LinkedHashSet<>();
for (RaidEntity entity : raidEntityList) {
activeRaids.add(getRaidInstance(entity));
}
return activeRaids;
}
Aggregations