Search in sources :

Example 6 with RaidEntity

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

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

Example 8 with RaidEntity

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

Example 9 with RaidEntity

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

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

Aggregations

RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)25 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)9 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)4 LocalTime (java.time.LocalTime)3 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Guild (net.dv8tion.jda.core.entities.Guild)1 User (net.dv8tion.jda.core.entities.User)1 RaidExistsException (pokeraidbot.domain.errors.RaidExistsException)1 RaidNotFoundException (pokeraidbot.domain.errors.RaidNotFoundException)1 Gym (pokeraidbot.domain.gym.Gym)1 SignUp (pokeraidbot.domain.raid.signup.SignUp)1 Config (pokeraidbot.infrastructure.jpa.config.Config)1