Skip to content

Commit

Permalink
Fix calendar and add lang type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Apr 5, 2024
1 parent 4f9db1e commit 13a110f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.LangType

data class WeeklyAnimeDto(
val anime: AnimeDto,
val releaseDateTime: String,
val langType: LangType,
val platforms: List<PlatformDto>
)
4 changes: 2 additions & 2 deletions src/main/kotlin/fr/shikkanime/entities/enums/CountryCode.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.shikkanime.entities.enums

enum class CountryCode(val locale: String, val voice: String) {
FR("fr-FR", "VF"),
enum class CountryCode(val locale: String, val voice: String, val timezone: String) {
FR("fr-FR", "VF", "Europe/Paris"),
;

companion object {
Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/fr/shikkanime/services/AnimeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import fr.shikkanime.utils.StringUtils.capitalizeWords
import fr.shikkanime.utils.withUTC
import io.ktor.http.*
import java.time.LocalDate
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.*
Expand Down Expand Up @@ -54,29 +55,33 @@ class AnimeService : AbstractService<Anime, AnimeRepository>() {
fun findAllUUIDAndImage() = animeRepository.findAllUUIDAndImage()

fun getWeeklyAnimes(startOfWeekDay: LocalDate, countryCode: CountryCode): List<WeeklyAnimesDto> {
val zoneId = ZoneId.of(countryCode.timezone)
val start = startOfWeekDay.minusDays(7).atStartOfDay(Constant.utcZoneId)
val end = startOfWeekDay.plusDays(7).atTime(23, 59, 59).withUTC()
val list = episodeService.findAllByDateRange(countryCode, start, end)
val pattern = DateTimeFormatter.ofPattern("EEEE", Locale.forLanguageTag(countryCode.locale))

return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).toList().map { date ->
val zonedDate = date.atStartOfDay(zoneId)
val dateTitle = date.format(pattern).capitalizeWords()
val episodes = list.filter { it.releaseDateTime.dayOfWeek == date.dayOfWeek }
.sortedWith(compareBy({ it.releaseDateTime.toLocalTime() }, { it.anime?.name?.lowercase() }))
val episodes =
list.filter { it.releaseDateTime.withZoneSameInstant(zoneId).dayOfWeek == zonedDate.dayOfWeek }

WeeklyAnimesDto(
dateTitle,
episodes.distinctBy { episode -> episode.anime?.uuid }.map { distinctEpisode ->
episodes.distinctBy { episode -> episode.anime?.uuid.toString() + episode.langType.toString() }
.map { distinctEpisode ->
val platforms = episodes.filter { it.anime?.uuid == distinctEpisode.anime?.uuid }
.mapNotNull(Episode::platform)
.distinct()

WeeklyAnimeDto(
AbstractConverter.convert(distinctEpisode.anime, AnimeNoStatusDto::class.java).toAnimeDto(),
distinctEpisode.releaseDateTime.withUTC().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
distinctEpisode.langType!!,
AbstractConverter.convert(platforms, PlatformDto::class.java)
)
}
}.sortedBy { ZonedDateTime.parse(it.releaseDateTime).withZoneSameInstant(zoneId).toLocalTime() }
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/css/purged/bootstrap.min.css

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions src/main/resources/templates/site/calendar.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@
</div>
</div>

<div class="mt-1 mx-2">
<span class="h6 text-truncate-2 mb-0 fw-bold">${release.anime.shortName}</span>
<span class="text-muted mt-0 mb-1"
data-release-date-time="${release.releaseDateTime}"></span>
<div class="mx-2">
<div class="d-flex align-items-center py-1">
<span class="text-muted"
data-release-date-time="${release.releaseDateTime}"></span>
<div class="vr mx-2"></div>
<div class="d-block mt-2">
<span class="h6 text-truncate-2 mb-0 fw-bold">${release.anime.shortName}</span>
<p class="text-muted mt-0 mb-1"><#if release.langType == 'SUBTITLES'>Sous-titrage<#else>Doublage</#if></p>
</div>
</div>
</div>

<div class="bg-black bg-opacity-75 bg-blur position-absolute top-0 start-0 w-100 h-100 mh-100 p-3 rounded-4"
Expand Down Expand Up @@ -73,7 +79,7 @@
releaseDateTimeElements.forEach(element => {
const releaseDateTime = new Date(element.getAttribute('data-release-date-time'));
element.innerHTML = releaseDateTime.toLocaleTimeString().split(':').slice(0, 2).join(':');
element.textContent = releaseDateTime.toLocaleTimeString().split(':').slice(0, 2).join(':');
});
</script>
</@navigation.display>
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ internal class AnimeControllerTest {
assertEquals(HttpStatusCode.OK, status)
val weeklyAnimesDtos = ObjectParser.fromJson(bodyAsText(), Array<WeeklyAnimesDto>::class.java)
assertEquals(7, weeklyAnimesDtos.size)
assertEquals(4, weeklyAnimesDtos[0].releases.size)
assertEquals(8, weeklyAnimesDtos[0].releases.size)
}
}

Expand Down

0 comments on commit 13a110f

Please sign in to comment.