use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.
the class RaidRepository method addSignUp.
public void addSignUp(User user, Raid raid, SignUp theSignUp) {
RaidEntity entity = findEntityByRaidId(raid.getId());
RaidEntitySignUp entitySignUp = entity.getSignUp(user.getName());
if (entitySignUp == null) {
entity.addSignUp(new RaidEntitySignUp(user.getName(), theSignUp.getHowManyPeople(), Utils.printTime(theSignUp.getArrivalTime())));
} else {
entitySignUp.setNumberOfPeople(theSignUp.getHowManyPeople(), localeService, user);
entitySignUp.setEta(Utils.printTime(theSignUp.getArrivalTime()));
}
raidEntityRepository.save(entity);
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.
the class RaidRepository method listGroupsForRaid.
public String listGroupsForRaid(Raid raid, Set<RaidGroup> groups) {
StringBuilder sb = new StringBuilder();
if (groups.size() > 0) {
sb.append(" " + Emotes.GROUP + " ");
Set<String> times = new LinkedHashSet<>();
int signUpsInGroups = 0;
for (RaidGroup group : groups) {
final LocalTime groupTime = group.getStartsAt().toLocalTime();
final int numberOfPeopleInGroup = countSignups(raid.getSignUpsAt(groupTime));
times.add(printTime(groupTime) + " (**" + numberOfPeopleInGroup + "**)");
signUpsInGroups += numberOfPeopleInGroup;
}
sb.append(StringUtils.join(times, ", "));
RaidEntity entity = findEntityByRaidId(raid.getId());
final Set<RaidEntitySignUp> signUpsAsSet = entity.getSignUpsAsSet();
final long totalSignUps = signUpsAsSet.stream().mapToInt(RaidEntitySignUp::getNumberOfPeople).sum();
if (totalSignUps > signUpsInGroups) {
sb.append(", -:- (**").append(totalSignUps - signUpsInGroups).append("**)");
}
}
return sb.toString();
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp 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.RaidEntitySignUp 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.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.
the class RaidRepository method executeUnsignCommand.
public String executeUnsignCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
String people = args[0];
String userName = user.getName();
if (args.length < 2 || args.length > 10) {
throw new WrongNumberOfArgumentsException(user, localeService, 2, args.length, help);
}
Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 1; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
Raid raid = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
final RaidEntitySignUp signUp = findEntityByRaidId(raid.getId()).getSignUp(user.getName());
if (signUp == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, user.getName(), gym.getName()));
}
raid = removeFromSignUp(raid.getId(), user, 0, 0, 0, numberOfPeople, LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), signUp.getArrivalTime()));
final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
final Set<SignUp> signUps = raid.getSignUps();
Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
final String allSignUpNames = StringUtils.join(signUpNames, ", ");
final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
return localeService.getMessageFor(LocaleService.UNSIGN, localeForUser, userName, gym.getName(), signUpText);
}
Aggregations