Skip to content

Commit

Permalink
Fix display and change to updated DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Feb 13, 2024
1 parent 92e1fbf commit 945c042
Show file tree
Hide file tree
Showing 24 changed files with 214 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.controllers.admin

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.Link
import fr.shikkanime.services.AnimeService
import fr.shikkanime.utils.routes.AdminSessionAuthenticated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.controllers.api

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.services.SimulcastService
import fr.shikkanime.utils.routes.*
import fr.shikkanime.utils.routes.method.Get
Expand Down
17 changes: 13 additions & 4 deletions src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ class SiteController {
@Path("sitemap.xml")
@Get
private fun sitemap(): Response {
val simulcasts = simulcastCacheService.findAll()!!
val animes = animeCacheService.findAll()!!
val simulcasts = simulcastCacheService.findAllUpdated()!!

val animes = simulcasts.flatMap {

Check warning on line 76 in src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt#L76

Added line #L76 was not covered by tests
animeCacheService.findAllByUpdated(
CountryCode.FR,
it.uuid,
listOf(SortParameter("name", SortParameter.Order.ASC)),
1,
102
)!!.data

Check warning on line 83 in src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt#L78-L83

Added lines #L78 - L83 were not covered by tests
}

val episode = episodeCacheService.findAllBy(
CountryCode.FR,
Expand All @@ -87,8 +96,8 @@ class SiteController {
null,
mutableMapOf(
"episode" to episode,
"simulcasts" to simulcasts,
"animes" to animes
"simulcastsUpdated" to simulcasts,
"animesUpdated" to animes

Check warning on line 100 in src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt#L99-L100

Added lines #L99 - L100 were not covered by tests
),
contentType = ContentType.Text.Xml
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.enums.CountryCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.services.caches.EpisodeCacheService
import fr.shikkanime.utils.StringUtils
import fr.shikkanime.utils.withUTC
import org.apache.tika.language.detect.LanguageDetector
Expand All @@ -17,24 +14,13 @@ import java.time.format.DateTimeFormatter
class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()

@Inject
private lateinit var episodeCacheService: EpisodeCacheService

override fun convert(from: Anime): AnimeDto {
val lastReleaseDate = episodeCacheService.findAllBy(
from.countryCode!!,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

val status = if (
from.image.isNullOrBlank() ||
from.banner.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode.name.lowercase()
languageDetector.detect(from.description).language.lowercase() != from.countryCode!!.name.lowercase()
) Status.INVALID else Status.VALID

return AnimeDto(
Expand All @@ -43,7 +29,7 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
image = from.image,
banner = from.banner,
countryCode = from.countryCode,
countryCode = from.countryCode!!,
name = from.name!!,
shortName = StringUtils.getShortName(from.name!!),
description = from.description,
Expand All @@ -53,7 +39,6 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
) else null,
status = status,
slug = from.slug,
lastReleaseDateTime = lastReleaseDate
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.animes.UpdatedAnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.services.caches.EpisodeCacheService
import fr.shikkanime.utils.StringUtils
import fr.shikkanime.utils.withUTC
import org.apache.tika.language.detect.LanguageDetector
import org.hibernate.Hibernate
import java.time.format.DateTimeFormatter

class AnimeToUpdatedAnimeDtoConverter : AbstractConverter<Anime, UpdatedAnimeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()

@Inject
private lateinit var episodeCacheService: EpisodeCacheService

override fun convert(from: Anime): UpdatedAnimeDto {
val lastReleaseDate = episodeCacheService.findAllBy(
from.countryCode!!,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1

Check warning on line 29 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L25-L29

Added lines #L25 - L29 were not covered by tests
)?.data?.firstOrNull()?.releaseDateTime

val status = if (

Check warning on line 32 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L32

Added line #L32 was not covered by tests
from.image.isNullOrBlank() ||
from.banner.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode.name.lowercase()
) Status.INVALID else Status.VALID

Check warning on line 38 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L38

Added line #L38 was not covered by tests

return UpdatedAnimeDto(
uuid = from.uuid,
releaseDateTime = from.releaseDateTime.withUTC()
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
image = from.image,
banner = from.banner,
countryCode = from.countryCode,
name = from.name!!,
shortName = StringUtils.getShortName(from.name!!),
description = from.description,

Check warning on line 49 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L40-L49

Added lines #L40 - L49 were not covered by tests
simulcasts = if (Hibernate.isInitialized(from.simulcasts)) convert(
from.simulcasts,

Check warning on line 51 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L51

Added line #L51 was not covered by tests
SimulcastDto::class.java
) else null,
status = status,
slug = from.slug,
lastReleaseDateTime = lastReleaseDate

Check warning on line 56 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L53-L56

Added lines #L53 - L56 were not covered by tests
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.shikkanime.converters.episode

import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.EpisodeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.Episode
import fr.shikkanime.utils.withUTC
import java.time.format.DateTimeFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.services.SimulcastService

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.services.caches.AnimeCacheService

class SimulcastToSimulcastDtoConverter : AbstractConverter<Simulcast, SimulcastDto>() {
@Inject
private lateinit var animeCacheService: AnimeCacheService

override fun convert(from: Simulcast): SimulcastDto {
val lastReleaseDateTime = animeCacheService.findAllBy(
CountryCode.FR,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

return SimulcastDto(
uuid = from.uuid,
season = from.season!!,
Expand All @@ -33,7 +18,6 @@ class SimulcastToSimulcastDtoConverter : AbstractConverter<Simulcast, SimulcastD
"AUTUMN" -> "Automne"
else -> "Inconnu"
} + " ${from.year}",
lastReleaseDateTime = lastReleaseDateTime
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.simulcasts.UpdatedSimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.services.caches.AnimeCacheService

class SimulcastToUpdatedSimulcastDtoConverter : AbstractConverter<Simulcast, UpdatedSimulcastDto>() {
@Inject
private lateinit var animeCacheService: AnimeCacheService

override fun convert(from: Simulcast): UpdatedSimulcastDto {
val lastReleaseDateTime = animeCacheService.findAllBy(
CountryCode.FR,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1

Check warning on line 21 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L17-L21

Added lines #L17 - L21 were not covered by tests
)?.data?.firstOrNull()?.releaseDateTime

return UpdatedSimulcastDto(
uuid = from.uuid,
season = from.season!!,
year = from.year!!,
slug = "${from.season.lowercase()}-${from.year}",

Check warning on line 28 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L24-L28

Added lines #L24 - L28 were not covered by tests
label = when (from.season) {
"WINTER" -> "Hiver"
"SPRING" -> "Printemps"
"SUMMER" -> "Été"
"AUTUMN" -> "Automne"
else -> "Inconnu"
} + " ${from.year}",
lastReleaseDateTime = lastReleaseDateTime

Check warning on line 36 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L30-L36

Added lines #L30 - L36 were not covered by tests
)
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/dtos/EpisodeDto.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.entities.enums.Platform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.shikkanime.dtos
package fr.shikkanime.dtos.animes

import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.enums.CountryCode
import java.io.Serializable
import java.util.*
Expand All @@ -17,5 +18,4 @@ data class AnimeDto(
val simulcasts: List<SimulcastDto>?,
val status: Status? = null,
val slug: String? = null,
val lastReleaseDateTime: String? = null
) : Serializable
22 changes: 22 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/animes/UpdatedAnimeDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.shikkanime.dtos.animes

import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.enums.CountryCode
import java.io.Serializable
import java.util.*

data class UpdatedAnimeDto(
val uuid: UUID?,
val countryCode: CountryCode,
var name: String,
var shortName: String,
var releaseDateTime: String,
val image: String? = null,
val banner: String? = null,
val description: String?,
val simulcasts: List<SimulcastDto>?,
val status: Status? = null,
val slug: String? = null,
val lastReleaseDateTime: String? = null
) : Serializable

Check warning on line 22 in src/main/kotlin/fr/shikkanime/dtos/animes/UpdatedAnimeDto.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/dtos/animes/UpdatedAnimeDto.kt#L9-L22

Added lines #L9 - L22 were not covered by tests
12 changes: 12 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/simulcasts/SimulcastDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.shikkanime.dtos.simulcasts

import java.io.Serializable
import java.util.*

data class SimulcastDto(
val uuid: UUID?,
val season: String,
val year: Int,
val slug: String,
val label: String,
) : Serializable
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fr.shikkanime.dtos
package fr.shikkanime.dtos.simulcasts

import java.io.Serializable
import java.util.*

data class SimulcastDto(
data class UpdatedSimulcastDto(

Check warning on line 6 in src/main/kotlin/fr/shikkanime/dtos/simulcasts/UpdatedSimulcastDto.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/dtos/simulcasts/UpdatedSimulcastDto.kt#L6

Added line #L6 was not covered by tests
val uuid: UUID?,
val season: String,
val year: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.google.inject.Inject
import fr.shikkanime.caches.CountryCodeNamePaginationKeyCache
import fr.shikkanime.caches.CountryCodeUUIDSortPaginationKeyCache
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.PageableDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.animes.UpdatedAnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
Expand All @@ -25,6 +26,14 @@ class AnimeCacheService : AbstractCacheService() {
)
}

private val findAllByUpdatedCache =
MapCache<CountryCodeUUIDSortPaginationKeyCache, PageableDto<UpdatedAnimeDto>>(classes = listOf(Anime::class.java)) {
PageableDto.fromPageable(

Check warning on line 31 in src/main/kotlin/fr/shikkanime/services/caches/AnimeCacheService.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/services/caches/AnimeCacheService.kt#L31

Added line #L31 was not covered by tests
animeService.findAllBy(it.countryCode, it.uuid, it.sort, it.page, it.limit),
UpdatedAnimeDto::class.java
)
}

private val findAllByNameCache = MapCache<CountryCodeNamePaginationKeyCache, PageableDto<AnimeDto>>(classes = listOf(Anime::class.java)) {
PageableDto.fromPageable(
animeService.findAllByName(it.name, it.countryCode, it.page, it.limit),
Expand Down Expand Up @@ -52,6 +61,14 @@ class AnimeCacheService : AbstractCacheService() {
limit: Int
) = findAllByCache[CountryCodeUUIDSortPaginationKeyCache(countryCode, uuid, sort, page, limit)]

fun findAllByUpdated(
countryCode: CountryCode?,
uuid: UUID?,
sort: List<SortParameter>,
page: Int,
limit: Int
) = findAllByUpdatedCache[CountryCodeUUIDSortPaginationKeyCache(countryCode, uuid, sort, page, limit)]

Check warning on line 70 in src/main/kotlin/fr/shikkanime/services/caches/AnimeCacheService.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/services/caches/AnimeCacheService.kt#L70

Added line #L70 was not covered by tests

fun findAllByName(name: String, countryCode: CountryCode?, page: Int, limit: Int) =
findAllByNameCache[CountryCodeNamePaginationKeyCache(countryCode, name, page, limit)]

Expand Down
Loading

0 comments on commit 945c042

Please sign in to comment.