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