Search in sources :

Example 1 with Episode

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

the class EpisodeResource method updateEpisode.

/**
 * PUT  /episodes : Updates an existing episode.
 *
 * @param episode the episode to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated episode,
 * or with status 400 (Bad Request) if the episode is not valid,
 * or with status 500 (Internal Server Error) if the episode couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/episodes")
@Timed
public ResponseEntity<Episode> updateEpisode(@RequestBody Episode episode) throws URISyntaxException {
    log.debug("REST request to update Episode : {}", episode);
    if (episode.getId() == null) {
        return createEpisode(episode);
    }
    Episode result = episodeRepository.save(episode);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, episode.getId().toString())).body(result);
}
Also used : Episode(com.furyviewer.domain.Episode) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with Episode

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

the class EpisodeResource method getEpisode.

/**
 * GET  /episodes/:id : get the "id" episode.
 *
 * @param id the id of the episode to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the episode, or with status 404 (Not Found)
 */
@GetMapping("/episodes/{id}")
@Timed
public ResponseEntity<Episode> getEpisode(@PathVariable Long id) {
    log.debug("REST request to get Episode : {}", id);
    Episode episode = episodeRepository.findOne(id);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(episode));
}
Also used : Episode(com.furyviewer.domain.Episode) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with Episode

use of com.furyviewer.domain.Episode 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 4 with Episode

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

the class EpisodeResourceIntTest method equalsVerifier.

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

Example 5 with Episode

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

the class EpisodeResourceIntTest method createEpisode.

@Test
@Transactional
public void createEpisode() throws Exception {
    int databaseSizeBeforeCreate = episodeRepository.findAll().size();
    // Create the Episode
    restEpisodeMockMvc.perform(post("/api/episodes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(episode))).andExpect(status().isCreated());
    // Validate the Episode in the database
    List<Episode> episodeList = episodeRepository.findAll();
    assertThat(episodeList).hasSize(databaseSizeBeforeCreate + 1);
    Episode testEpisode = episodeList.get(episodeList.size() - 1);
    assertThat(testEpisode.getNumber()).isEqualTo(DEFAULT_NUMBER);
    assertThat(testEpisode.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testEpisode.getDuration()).isEqualTo(DEFAULT_DURATION);
    assertThat(testEpisode.getReleaseDate()).isEqualTo(DEFAULT_RELEASE_DATE);
}
Also used : Episode(com.furyviewer.domain.Episode) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Episode (com.furyviewer.domain.Episode)8 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 Season (com.furyviewer.domain.Season)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 Crew (com.furyviewer.service.dto.TheMovieDB.Season.Crew)1 SeasonTmdbDTO (com.furyviewer.service.dto.TheMovieDB.Season.SeasonTmdbDTO)1 EpisodesHomeDTO (com.furyviewer.service.dto.util.EpisodesHomeDTO)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 IOException (java.io.IOException)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