use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method removeSignUp.
public void removeSignUp(User user, Raid raid, SignUp theSignUp) {
RaidEntity entity = findEntityByRaidId(raid.getId());
entity.removeSignUp(new RaidEntitySignUp(user.getName(), theSignUp.getHowManyPeople(), Utils.printTime(theSignUp.getArrivalTime())));
raidEntityRepository.save(entity);
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method removeAllSignUpsAt.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Raid removeAllSignUpsAt(String raidId, LocalDateTime startAt) {
Validate.notNull(raidId, "Raid ID cannot be null");
Validate.notNull(startAt, "Start time cannot be null");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("About to remove signups for raid " + raidId + " at " + printTimeIfSameDay(startAt));
}
RaidEntity entity = findEntityByRaidId(raidId);
if (entity != null) {
for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
if (signUp.getArrivalTime().equals(startAt.toLocalTime())) {
RaidEntitySignUp removed = entity.removeSignUp(signUp);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Removed signup: " + removed);
}
}
}
entity = raidEntityRepository.save(entity);
}
return getRaidInstance(entity);
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method newGroupForRaid.
public RaidGroup newGroupForRaid(User user, RaidGroup group, Raid raid, Guild guild, Config config) {
Validate.notNull(user, "User");
Validate.notNull(group, "Group");
Validate.notNull(raid, "Raid");
Validate.notEmpty(raid.getId(), "Raid ID");
RaidEntity raidEntity = findEntityByRaidId(raid.getId());
final boolean added = raidEntity.addGroup(group);
if (!added) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.GROUP_NOT_ADDED, localeService.getLocaleForUser(user), String.valueOf(raid)));
}
return group;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method removeFromSignUp.
public Raid removeFromSignUp(String raidId, User user, int mystic, int instinct, int valor, int plebs, LocalDateTime startAt) {
RaidEntity raidEntity = findEntityByRaidId(raidId);
if (raidEntity == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
RaidEntitySignUp signUp = raidEntity.getSignUp(user.getName());
final String startAtTime = Utils.printTime(startAt.toLocalTime());
if (signUp == null) {
// Ignore this case, when there is no signup to remove from. Silent ignore.
} else if (startAtTime.equals(signUp.getEta())) {
final int sum = signUp.getNumberOfPeople() - mystic - instinct - valor - plebs;
if (sum <= 0) {
// Remove signup
raidEntity.removeSignUp(signUp);
} else {
signUp.setNumberOfPeople(sum, localeService, user);
}
raidEntity = raidEntityRepository.save(raidEntity);
} else {
// Ignore if they're trying to remove signups for a group they're no longer signed up for - we let them untick their emote
}
return getRaidInstance(raidEntity);
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getAllRaidsForRegion.
public Set<Raid> getAllRaidsForRegion(String region) {
removeExpiredRaids(region);
List<RaidEntity> raidEntityList = raidEntityRepository.findByRegionOrderByPokemonAscEndOfRaidAsc(region);
Set<Raid> activeRaids = new LinkedHashSet<>();
for (RaidEntity entity : raidEntityList) {
activeRaids.add(getRaidInstance(entity));
}
return activeRaids;
}
Aggregations