Search in sources :

Example 6 with RaidEntitySignUp

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);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 7 with RaidEntitySignUp

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();
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) LocalTime(java.time.LocalTime) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 8 with RaidEntitySignUp

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);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 9 with RaidEntitySignUp

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);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with RaidEntitySignUp

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);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) WrongNumberOfArgumentsException(pokeraidbot.domain.errors.WrongNumberOfArgumentsException) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

Aggregations

RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)11 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)9 Transactional (org.springframework.transaction.annotation.Transactional)3 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)3 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 LocalTime (java.time.LocalTime)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WrongNumberOfArgumentsException (pokeraidbot.domain.errors.WrongNumberOfArgumentsException)1 Gym (pokeraidbot.domain.gym.Gym)1 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)1