Search in sources :

Example 1 with EpisodesHomeDTO

use of com.furyviewer.service.dto.util.EpisodesHomeDTO 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)

Aggregations

Episode (com.furyviewer.domain.Episode)1 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 EpisodesHomeDTO (com.furyviewer.service.dto.util.EpisodesHomeDTO)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