Search in sources :

Example 21 with RaidEntity

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

Example 22 with RaidEntity

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

Example 23 with RaidEntity

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

Example 24 with RaidEntity

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

Example 25 with 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;
}
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