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);
}
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));
}
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;
}
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);
}
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);
}
Aggregations