diff --git a/src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt b/src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt index 8c53e611..206f6d48 100644 --- a/src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt +++ b/src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt @@ -1,10 +1,12 @@ package fr.shikkanime.dtos +import fr.shikkanime.dtos.variants.EpisodeVariantWithoutMappingDto import fr.shikkanime.entities.enums.LangType data class WeeklyAnimeDto( val anime: AnimeDto, val releaseDateTime: String, val langType: LangType, - val platforms: List + val platforms: List, + val variant: EpisodeVariantWithoutMappingDto? ) diff --git a/src/main/kotlin/fr/shikkanime/services/AnimeService.kt b/src/main/kotlin/fr/shikkanime/services/AnimeService.kt index 795ffc4b..d2ba2ee8 100644 --- a/src/main/kotlin/fr/shikkanime/services/AnimeService.kt +++ b/src/main/kotlin/fr/shikkanime/services/AnimeService.kt @@ -7,6 +7,7 @@ import fr.shikkanime.dtos.PlatformDto import fr.shikkanime.dtos.WeeklyAnimeDto import fr.shikkanime.dtos.WeeklyAnimesDto import fr.shikkanime.dtos.enums.Status +import fr.shikkanime.dtos.variants.EpisodeVariantWithoutMappingDto import fr.shikkanime.entities.* import fr.shikkanime.entities.enums.CountryCode import fr.shikkanime.entities.enums.LangType @@ -19,6 +20,7 @@ import java.time.LocalDate import java.time.ZoneId import java.time.ZonedDateTime import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoField import java.util.* class AnimeService : AbstractService() { @@ -70,9 +72,8 @@ class AnimeService : AbstractService() { return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).toList().map { date -> val zonedDate = date.atStartOfDay(zoneId) - val episodeVariants = list.filter { - it.releaseDateTime.withZoneSameInstant(zoneId).dayOfWeek == zonedDate.dayOfWeek - } + val episodeVariants = list.sortedByDescending { it.releaseDateTime } + .filter { it.releaseDateTime.withZoneSameInstant(zoneId).dayOfWeek == zonedDate.dayOfWeek } WeeklyAnimesDto( date.format(DateTimeFormatter.ofPattern("EEEE", Locale.forLanguageTag(countryCode.locale))) @@ -92,7 +93,13 @@ class AnimeService : AbstractService() { .sorted() .distinct(), PlatformDto::class.java - )!! + )!!, + // If variant is same week as startOfWeekDay, return it + if (distinctVariant.releaseDateTime.withZoneSameInstant(zoneId)[ChronoField.ALIGNED_WEEK_OF_YEAR] == startOfWeekDay[ChronoField.ALIGNED_WEEK_OF_YEAR]) { + AbstractConverter.convert(distinctVariant, EpisodeVariantWithoutMappingDto::class.java) + } else { + null + } ) }.sortedWith(compareBy({ ZonedDateTime.parse(it.releaseDateTime).withZoneSameInstant(zoneId).toLocalTime() diff --git a/src/main/resources/templates/site/calendar.ftl b/src/main/resources/templates/site/calendar.ftl index 06c8398a..6ce33c03 100644 --- a/src/main/resources/templates/site/calendar.ftl +++ b/src/main/resources/templates/site/calendar.ftl @@ -57,10 +57,27 @@