Skip to content

Commit

Permalink
Change calendar calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Mar 26, 2024
1 parent bb0cd18 commit 6bda5b4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ val junitVersion = "5.10.2"
val h2Version = "2.2.224"

plugins {
kotlin("jvm") version "1.9.23"
kotlin("jvm") version "2.0.0-Beta5"
id("io.ktor.plugin") version "2.3.9"
jacoco
id("org.sonarqube") version "4.4.1.3373"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/shikkanime/entities/Anime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Anime(
var banner: String? = null,
@Column(nullable = true, columnDefinition = "VARCHAR(2000)")
var description: String? = null,
@ManyToMany
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "anime_simulcast",
joinColumns = [JoinColumn(name = "anime_uuid")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,20 @@ class EpisodeRepository : AbstractRepository<Episode>() {
countryCode: CountryCode,
start: ZonedDateTime,
end: ZonedDateTime,
blacklisted: List<UUID>,
): List<Episode> {
return inTransaction { entityManager ->
createReadOnlyQuery(
entityManager,
"""
FROM Episode e
WHERE e.anime.countryCode = :countryCode AND e.releaseDateTime BETWEEN :start AND :end AND e.anime.uuid NOT IN :blacklisted
ORDER BY e.releaseDateTime ASC
FROM Episode e
WHERE e.anime.countryCode = :countryCode AND e.releaseDateTime BETWEEN :start AND :end
ORDER BY e.releaseDateTime ASC, LOWER(e.anime.name) ASC
""".trimIndent(),
getEntityClass()
)
.setParameter("countryCode", countryCode)
.setParameter("start", start)
.setParameter("end", end)
.setParameter("blacklisted", blacklisted)
.resultList
.initialize()
}
Expand Down
30 changes: 14 additions & 16 deletions src/main/kotlin/fr/shikkanime/services/AnimeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,29 @@ class AnimeService : AbstractService<Anime, AnimeRepository>() {
fun findAllUUIDAndImage() = animeRepository.findAllUUIDAndImage()

fun getWeeklyAnimes(startOfWeekDay: LocalDate, countryCode: CountryCode): List<WeeklyAnimesDto> {
return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).map {
val start = ZonedDateTime.parse("${it}T00:00:00Z")
val end = ZonedDateTime.parse("${it}T23:59:59Z")
val dateTitle =
it.format(DateTimeFormatter.ofPattern("EEEE", Locale.of(countryCode.locale.split("-")[0], countryCode.locale.split("-")[1]))).capitalizeWords()
val list = episodeService.findAllByDateRange(countryCode, start, end, emptyList()).toMutableList()

list.addAll(
episodeService.findAllByDateRange(
countryCode,
start.minusDays(7),
end.minusDays(7),
list.mapNotNull { anime -> anime.uuid })
)
val start = ZonedDateTime.parse("${startOfWeekDay.minusDays(7)}T00:00:00Z")
val end = ZonedDateTime.parse("${startOfWeekDay.plusDays(7)}T23:59:59Z")
val list = episodeService.findAllByDateRange(countryCode, start, end).toMutableList()

return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).map { date ->
val dateTitle = date.format(
DateTimeFormatter.ofPattern(
"EEEE",
Locale.of(countryCode.locale.split("-")[0], countryCode.locale.split("-")[1])
)
).capitalizeWords()
val episodes = list.filter { it.releaseDateTime.dayOfWeek == date.dayOfWeek }

WeeklyAnimesDto(
dateTitle,
AbstractConverter.convert(
list.distinctBy { episode -> episode.anime?.uuid },
episodes.distinctBy { episode -> episode.anime?.uuid },
EpisodeDto::class.java
).map { episodeDto ->
WeeklyAnimeDto(
episodeDto.anime,
episodeDto.releaseDateTime,
AbstractConverter.convert(list.filter { episode -> episode.anime?.uuid == episodeDto.anime.uuid }
AbstractConverter.convert(episodes.filter { episode -> episode.anime?.uuid == episodeDto.anime.uuid }
.map { episode -> episode.platform!! }
.distinct(), PlatformDto::class.java)
)
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/fr/shikkanime/services/EpisodeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ class EpisodeService : AbstractService<Episode, EpisodeRepository>() {
fun findAllByDateRange(
countryCode: CountryCode,
start: ZonedDateTime,
end: ZonedDateTime,
blacklisted: List<UUID>
) = episodeRepository.findAllByDateRange(countryCode, start, end, blacklisted)
end: ZonedDateTime
) = episodeRepository.findAllByDateRange(countryCode, start, end)

fun addImage(uuid: UUID, image: String, bypass: Boolean = false) {
ImageService.add(uuid, ImageService.Type.IMAGE, image, 640, 360, bypass)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/css/purged/bootstrap.min.css

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions src/main/resources/templates/site/calendar.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class="img-fluid" width="640"
height="360">

<div class="position-absolute top-0 start-0 p-1">
<div class="position-absolute top-0 end-0 p-1">
<div class="d-flex">
<#list release.platforms as platform>
<img src="https://www.shikkanime.fr/assets/img/platforms/${platform.image}"
Expand All @@ -38,15 +38,13 @@
</#list>
</div>
</div>

<div class="position-absolute bottom-0 start-0 p-1 px-md-3 bg-black"
data-release-date-time="${release.releaseDateTime}">
</div>
</div>

<span class="h6 mt-1 mb-3 text-truncate-2">
${release.anime.shortName}
</span>
<div class="mt-1 mb-2">
<span class="h6 text-truncate-2 mb-0">${release.anime.shortName}</span>
<span class="text-muted mt-0"
data-release-date-time="${release.releaseDateTime}"></span>
</div>

<div class="bg-black bg-opacity-75 position-absolute top-0 start-0 w-100 h-100 mh-100 p-3"
x-show="hover">
Expand Down

0 comments on commit 6bda5b4

Please sign in to comment.