Search in sources :

Example 1 with Season

use of com.furyviewer.domain.Season in project FuryViewer by TheDoctor-95.

the class SeasonResourceIntTest method createSeason.

@Test
@Transactional
public void createSeason() throws Exception {
    int databaseSizeBeforeCreate = seasonRepository.findAll().size();
    // Create the Season
    restSeasonMockMvc.perform(post("/api/seasons").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(season))).andExpect(status().isCreated());
    // Validate the Season in the database
    List<Season> seasonList = seasonRepository.findAll();
    assertThat(seasonList).hasSize(databaseSizeBeforeCreate + 1);
    Season testSeason = seasonList.get(seasonList.size() - 1);
    assertThat(testSeason.getNumber()).isEqualTo(DEFAULT_NUMBER);
    assertThat(testSeason.getReleaseDate()).isEqualTo(DEFAULT_RELEASE_DATE);
}
Also used : Season(com.furyviewer.domain.Season) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Season

use of com.furyviewer.domain.Season in project FuryViewer by TheDoctor-95.

the class EpisodeService method getNextEpisodes.

public List<EpisodesHomeDTO> getNextEpisodes() {
    List<EpisodesHomeDTO> episodes = new ArrayList<>();
    seriesStatsRepository.followingSeriesUser(SecurityUtils.getCurrentUserLogin()).forEach(series -> {
        Optional<Season> maxSeasonSeenOptional = chapterSeenRepository.findBySeenAndEpisodeSeasonSeriesIdAndUserLogin(true, series.getId(), SecurityUtils.getCurrentUserLogin()).stream().map(chapterSeen -> chapterSeen.getEpisode().getSeason()).max(Comparator.comparing(com.furyviewer.domain.Season::getNumber));
        EpisodesHomeDTO episodesHomeDTO = new EpisodesHomeDTO();
        Episode nextEpisode;
        if (maxSeasonSeenOptional.isPresent()) {
            Season maxSeasonSeen = maxSeasonSeenOptional.get();
            Episode maxEpisodeSeen = chapterSeenRepository.findBySeenAndEpisodeSeasonSeriesIdAndUserLogin(true, series.getId(), SecurityUtils.getCurrentUserLogin()).stream().map(chapterSeen -> chapterSeen.getEpisode()).filter(episode -> episode.getSeason().equals(maxSeasonSeen)).max(Comparator.comparing(com.furyviewer.domain.Episode::getNumber)).get();
            if (maxEpisodeSeen.getNumber() < maxSeasonSeen.getEpisodes().size()) {
                nextEpisode = episodeRepository.findByNumberAndSeasonNumberAndSeasonSeriesId(maxEpisodeSeen.getNumber() + 1, maxSeasonSeen.getNumber(), series.getId());
            } else {
                nextEpisode = episodeRepository.findByNumberAndSeasonNumberAndSeasonSeriesId(1, maxSeasonSeen.getNumber() + 1, series.getId());
            }
        } else {
            nextEpisode = episodeRepository.findByNumberAndSeasonNumberAndSeasonSeriesId(1, 1, series.getId());
        }
        if (nextEpisode != null && (nextEpisode.getReleaseDate().isBefore(LocalDate.now()) || nextEpisode.getReleaseDate().isEqual(LocalDate.now()))) {
            episodesHomeDTO.setEpisodeNumber(nextEpisode.getNumber());
            episodesHomeDTO.setId(nextEpisode.getSeason().getSeries().getId());
            episodesHomeDTO.setSeasonNumber(nextEpisode.getSeason().getNumber());
            episodesHomeDTO.setTitleEpisode(nextEpisode.getName());
            episodesHomeDTO.setTitleSeries(nextEpisode.getSeason().getSeries().getName());
            episodesHomeDTO.setUrlCartel(nextEpisode.getSeason().getSeries().getImgUrl());
            episodes.add(episodesHomeDTO);
        }
    });
    return episodes;
}
Also used : Episode(com.furyviewer.domain.Episode) Autowired(org.springframework.beans.factory.annotation.Autowired) SecurityUtils(com.furyviewer.security.SecurityUtils) EpisodeRepository(com.furyviewer.repository.EpisodeRepository) ArrayList(java.util.ArrayList) SeriesStatsRepository(com.furyviewer.repository.SeriesStatsRepository) List(java.util.List) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) EpisodesHomeDTO(com.furyviewer.service.dto.util.EpisodesHomeDTO) Optional(java.util.Optional) Comparator(java.util.Comparator) Season(com.furyviewer.domain.Season) ChapterSeenRepository(com.furyviewer.repository.ChapterSeenRepository) Episode(com.furyviewer.domain.Episode) EpisodesHomeDTO(com.furyviewer.service.dto.util.EpisodesHomeDTO) ArrayList(java.util.ArrayList) Season(com.furyviewer.domain.Season)

Example 3 with Season

use of com.furyviewer.domain.Season in project FuryViewer by TheDoctor-95.

the class SeasonResource method createSeason.

/**
 * POST  /seasons : Create a new season.
 *
 * @param season the season to create
 * @return the ResponseEntity with status 201 (Created) and with body the new season, or with status 400 (Bad Request) if the season has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/seasons")
@Timed
public ResponseEntity<Season> createSeason(@RequestBody Season season) throws URISyntaxException {
    log.debug("REST request to save Season : {}", season);
    if (season.getId() != null) {
        throw new BadRequestAlertException("A new season cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Season result = seasonRepository.save(season);
    return ResponseEntity.created(new URI("/api/seasons/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) Season(com.furyviewer.domain.Season) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with Season

use of com.furyviewer.domain.Season in project FuryViewer by TheDoctor-95.

the class SeasonResourceIntTest method updateSeason.

@Test
@Transactional
public void updateSeason() throws Exception {
    // Initialize the database
    seasonRepository.saveAndFlush(season);
    int databaseSizeBeforeUpdate = seasonRepository.findAll().size();
    // Update the season
    Season updatedSeason = seasonRepository.findOne(season.getId());
    updatedSeason.number(UPDATED_NUMBER).releaseDate(UPDATED_RELEASE_DATE);
    restSeasonMockMvc.perform(put("/api/seasons").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedSeason))).andExpect(status().isOk());
    // Validate the Season in the database
    List<Season> seasonList = seasonRepository.findAll();
    assertThat(seasonList).hasSize(databaseSizeBeforeUpdate);
    Season testSeason = seasonList.get(seasonList.size() - 1);
    assertThat(testSeason.getNumber()).isEqualTo(UPDATED_NUMBER);
    assertThat(testSeason.getReleaseDate()).isEqualTo(UPDATED_RELEASE_DATE);
}
Also used : Season(com.furyviewer.domain.Season) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Season

use of com.furyviewer.domain.Season in project FuryViewer by TheDoctor-95.

the class SeasonResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Season.class);
    Season season1 = new Season();
    season1.setId(1L);
    Season season2 = new Season();
    season2.setId(season1.getId());
    assertThat(season1).isEqualTo(season2);
    season2.setId(2L);
    assertThat(season1).isNotEqualTo(season2);
    season1.setId(null);
    assertThat(season1).isNotEqualTo(season2);
}
Also used : Season(com.furyviewer.domain.Season) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Season (com.furyviewer.domain.Season)7 Timed (com.codahale.metrics.annotation.Timed)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Episode (com.furyviewer.domain.Episode)1 ChapterSeenRepository (com.furyviewer.repository.ChapterSeenRepository)1 EpisodeRepository (com.furyviewer.repository.EpisodeRepository)1 SeriesStatsRepository (com.furyviewer.repository.SeriesStatsRepository)1 SecurityUtils (com.furyviewer.security.SecurityUtils)1 EpisodesHomeDTO (com.furyviewer.service.dto.util.EpisodesHomeDTO)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1