Search in sources :

Example 11 with RaidEntitySignUp

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

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