Refactor and include new elements in details of anime

v5 v5.5.0
Jéluchu 2 months ago
parent c54a28967b
commit 93cf3816d6

@ -0,0 +1,27 @@
package com.jeluchu.core.models.jikan.anime
import com.jeluchu.core.models.jikan.search.Pagination
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Episodes(
@SerialName("mal_id")
val malId: Int? = 0,
@SerialName("title")
val title: String? = "",
@SerialName("episode")
val episode: String? = "",
@SerialName("url")
val url: String? = "",
/**
* Data list of all anime found.
*/
@SerialName("data")
val data: List<AnimeData>? = emptyList()
)

@ -39,6 +39,7 @@ object RssSources {
object Endpoints {
const val POSTS = "posts"
const val ANIME = "anime"
const val EPISODES = "episodes"
const val SCHEDULES = "schedules"
const val TOP_ANIME = "top/anime"
const val TOP_MANGA = "top/manga"
@ -63,6 +64,7 @@ object Routes {
const val ANITAKUME = "/anitakume"
const val CHARACTER = "/characters"
const val LAST_EPISODES = "/lastEpisodes"
const val EPISODES = "/episodes"
const val ID = "/{id}"
const val TYPE = "/{type}"
const val SEASON = "/{year}/{season}"
@ -76,6 +78,7 @@ object TimerKey {
const val LAST_UPDATED = "lastUpdated"
const val ANIME_TYPE = "anime_"
const val THEMES = "themes_"
const val EPISODES = "episodes_"
const val LAST_EPISODES = "last_episodes"
}
@ -87,11 +90,11 @@ object Collections {
const val ANITAKUME = "anitakume"
const val ANIME_THEMES = "anime_themes"
const val ARTISTS_INDEX = "artists_index"
const val ANIME_DETAILS = "anime_details"
const val LAST_EPISODES = "last_episodes"
const val ANIME_RANKING = "anime_ranking"
const val MANGA_RANKING = "manga_ranking"
const val PEOPLE_RANKING = "people_ranking"
const val ANIME_DIRECTORY = "anime_directory"
const val CHARACTER_RANKING = "character_ranking"
const val ANIME_PICTURES_QUERY = "anime_pictures_query"
const val ANIME_PICTURES_RECENT = "anime_pictures_recent"

@ -1,96 +1,104 @@
package com.jeluchu.features.anime.mappers
import com.jeluchu.features.themes.models.anime.AnimeThemeEntry
import com.jeluchu.core.extensions.*
import com.jeluchu.features.anime.models.anime.*
import com.jeluchu.features.anime.models.directory.AnimeTypeEntity
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity
import com.jeluchu.features.rankings.models.AnimeTopEntity
import com.jeluchu.features.rankings.models.CharacterTopEntity
import com.jeluchu.features.rankings.models.MangaTopEntity
import com.jeluchu.features.rankings.models.PeopleTopEntity
import com.jeluchu.features.schedule.models.DayEntity
import com.jeluchu.features.themes.models.anime.Anime
import com.jeluchu.features.themes.models.anime.AnimeVideoTheme
import com.jeluchu.features.themes.models.anime.AnimesEntity
import com.jeluchu.features.themes.models.anime.Video
import com.jeluchu.features.themes.models.anime.*
import org.bson.Document
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
fun documentToMoreInfoEntity(doc: Document): MoreInfoEntity {
return MoreInfoEntity(
id = doc.getObjectId("_id").toString(),
malId = doc.getIntSafe("malId"),
rank = doc.getIntSafe("rank"),
title = doc.getStringSafe("title"),
episodes = doc.getIntSafe("episodes"),
episodeList = doc.getListSafe<Document>("episodeList").map { documentToEpisodeInfo(it) },
type = doc.getStringSafe("type"),
status = doc.getStringSafe("status"),
season = doc.getDocumentSafe("season")?.let { documentToSeasonalEntity(it) },
poster = doc.getStringSafe("poster"),
cover = doc.getStringSafe("cover"),
genres = doc.getListSafe<String>("genres"),
synopsis = doc.getStringSafe("synopsis"),
episodes = doc.getListSafe<Document>("episodes").map { documentToMergedEpisode(it) },
episodesCount = doc.getIntSafe("episodesCount", 0),
duration = doc.getDocumentSafe("duration")?.let { documentToEpisodeDurationEntity(it) },
score = doc.getStringSafe("score"),
staff = doc.getListSafe<Document>("staff").map { documentToStaff(it) },
characters = doc.getListSafe<Document>("characters").map { documentToCharacter(it) },
status = doc.getStringSafe("status"),
type = doc.getStringSafe("type"),
url = doc.getStringSafe("url"),
promo = doc.getDocumentSafe("promo")?.let { documentToVideoPromo(it) },
duration = doc.getStringSafe("duration"),
rank = doc.getIntSafe("rank", 0),
titles = doc.getListSafe<Document>("titles").map { documentToAlternativeTitles(it) },
airing = doc.getBooleanSafe("airing"),
aired = doc.getDocumentSafe("aired")?.let { documentToAiringTime(it) } ?: AiringTime(),
broadcast = doc.getDocumentSafe("broadcast")?.let { documentToAnimeBroadcast(it) } ?: AnimeBroadcast(),
season = doc.getStringSafe("season"),
year = doc.getIntSafe("year", 0),
external = doc.getListSafe<Document>("external").map { documentToExternalLinks(it) },
streaming = doc.getListSafe<Document>("streaming").map { documentToExternalLinks(it) },
titles = doc.getDocumentSafe("titles")?.let { documentToOtherTitlesEntity(it) },
studios = doc.getListSafe<Document>("studios").map { documentToCompanies(it) },
licensors = doc.getListSafe<Document>("licensors").map { documentToCompanies(it) },
producers = doc.getListSafe<Document>("producers").map { documentToCompanies(it) },
theme = doc.getDocumentSafe("theme")?.let { documentToThemes(it) } ?: Themes(),
licensors = doc.getListSafe<Document>("licensors").map { documentToCompanies(it) },
relations = doc.getListSafe<Document>("relations").map { documentToRelated(it) },
stats = doc.getDocumentSafe("stats")?.let { documentToStatistics(it) } ?: Statistics(),
gallery = doc.getListSafe<Document>("gallery").map { documentToImageMediaEntity(it) },
episodeSource = doc.getStringSafe("episodeSource")
promo = doc.getDocumentSafe("promo")?.let { documentToVideoPromo(it) },
tags = doc.getDocumentSafe("genres")?.let { documentToMultipleLanguageLists(it) },
synopsis = doc.getDocumentSafe("synopsis")?.let { documentToMultipleLanguage(it) },
staff = doc.getListSafe<Document>("staff").map { documentToStaff(it) },
characters = doc.getListSafe<Document>("characters").map { documentToCharacter(it) },
streaming = doc.getListSafe<Document>("streaming").map { documentToExternalLinks(it) },
urls = doc.getListSafe<String>("urls").takeIf { it.isNotEmpty() } ?: listOf(doc.getStringSafe("url")).filter { it.isNotEmpty() },
broadcast = doc.getDocumentSafe("broadcast")?.let { documentToAnimeBroadcast(it) },
external = doc.getListSafe<Document>("external").map { documentToExternalLinks(it) },
stats = doc.getDocumentSafe("stats")?.let { documentToStatistics(it) },
nsfw = doc.getBooleanSafe("nsfw", false),
ageRating = doc.getStringSafe("ageRating"),
aired = doc.getDocumentSafe("aired")?.let { documentToAiringTime(it) },
themes = doc.getDocumentSafe("theme")?.let { documentToThemes(it) }
)
}
fun documentToActor(doc: Document): Actor {
return Actor(
person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(),
language = doc.getStringSafe("language")
fun documentToEpisodeInfo(doc: Document): EpisodeInfo {
return EpisodeInfo(
number = doc.getIntSafe("number"),
seasonNumber = doc.getIntSafe("season_number"),
relativeNumber = doc.getIntSafe("relative_number"),
airdate = doc.getStringSafe("airdate"),
duration = doc.getIntSafe("duration"),
thumbnail = doc.getStringSafe("thumbnail"),
synopsis = doc.getDocumentSafe("synopsis")?.let { documentToMultipleLanguage(it) },
titles = doc.getDocumentSafe("titles")?.let { documentToMultipleLanguageTitles(it) },
score = doc.getDoubleSafe("score"),
filler = doc.getBooleanSafe("filler", false),
recap = doc.getBooleanSafe("recap", false)
)
}
fun documentToAiringTime(doc: Document): AiringTime {
return AiringTime(
from = doc.getStringSafe("from"),
to = doc.getStringSafe("to")
fun documentToMultipleLanguage(doc: Document): MultipleLanguage {
return MultipleLanguage(
es = doc.getStringSafe("es"),
en = doc.getStringSafe("en")
)
}
fun documentToAlternativeTitles(doc: Document): AlternativeTitles {
return AlternativeTitles(
title = doc.getStringSafe("title"),
type = doc.getStringSafe("type")
fun documentToMultipleLanguageTitles(doc: Document): MultipleLanguageTitles {
return MultipleLanguageTitles(
es = doc.getStringSafe("es"),
en = doc.getStringSafe("en"),
jp = doc.getStringSafe("jp"),
romaji_jp = doc.getStringSafe("romaji_jp")
)
}
fun documentToAnimeBroadcast(doc: Document): AnimeBroadcast {
return AnimeBroadcast(
day = doc.getStringSafe("day"),
time = doc.getStringSafe("time"),
timezone = doc.getStringSafe("timezone")
fun documentToSeasonalEntity(doc: Document): SeasonalEntity {
return SeasonalEntity(
station = doc.getStringSafe("station"),
year = doc.getIntSafe("year")
)
}
fun documentToCharacter(doc: Document): Character {
return Character(
character = doc.getDocumentSafe("character")?.let { documentToIndividual(it) } ?: Individual(),
role = doc.getStringSafe("role"),
voiceActor = doc.getListSafe<Document>("voiceActor").map { documentToActor(it) }
fun documentToEpisodeDurationEntity(doc: Document): EpisodeDurationEntity {
return EpisodeDurationEntity(
unit = doc.getStringSafe("unit"),
value = doc.getIntSafe("value")
)
}
fun documentToOtherTitlesEntity(doc: Document): OtherTitlesEntity {
return OtherTitlesEntity(
synonyms = doc.getListSafe<String>("synonyms"),
abbreviatedTitles = doc.getListSafe<String>("abbreviated_titles")
)
}
@ -103,20 +111,19 @@ fun documentToCompanies(doc: Document): Companies {
)
}
fun documentToExternalLinks(doc: Document): ExternalLinks {
return ExternalLinks(
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name")
fun documentToRelated(doc: Document): Related {
return Related(
entry = doc.getListSafe<Document>("entry").map { documentToCompanies(it) },
relation = doc.getStringSafe("relation")
)
}
fun documentToImageMediaEntity(doc: Document): ImageMediaEntity {
return ImageMediaEntity(
media = doc.getStringSafe("media"),
thumbnail = doc.getStringSafe("thumbnail"),
width = doc.getIntSafe("width", 0),
height = doc.getIntSafe("height", 0),
url = doc.getStringSafe("url")
fun documentToVideoPromo(doc: Document): VideoPromo {
return VideoPromo(
embedUrl = doc.getStringSafe("embedUrl"),
url = doc.getStringSafe("url"),
youtubeId = doc.getStringSafe("youtubeId"),
images = doc.getDocumentSafe("images")?.let { documentToImages(it) } ?: Images()
)
}
@ -130,51 +137,51 @@ fun documentToImages(doc: Document): Images {
)
}
fun documentToIndividual(doc: Document): Individual {
return Individual(
malId = doc.getIntSafe("malId", 0),
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images")
fun documentToMultipleLanguageLists(doc: Document): MultipleLanguageLists {
return MultipleLanguageLists(
es = doc.getListSafe<String>("es"),
en = doc.getListSafe<String>("en")
)
}
fun documentToMergedEpisode(doc: Document): MergedEpisode {
return MergedEpisode(
malId = doc.getIntSafe("malId"),
title = doc.getStringSafe("title"),
titleJapanese = doc.getStringSafe("titleJapanese"),
titleRomanji = doc.getStringSafe("titleRomanji"),
aired = doc.getStringSafe("aired", ZonedDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)),
score = doc.getFloatSafe("score"),
filler = doc.getBooleanSafe("filler"),
recap = doc.getBooleanSafe("recap")
fun documentToStaff(doc: Document): Staff {
return Staff(
person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(),
positions = doc.getListSafe<String>("positions")
)
}
fun documentToRelated(doc: Document): Related {
return Related(
entry = doc.getListSafe<Document>("entry").map { documentToCompanies(it) },
relation = doc.getStringSafe("relation")
fun documentToCharacter(doc: Document): Character {
return Character(
malId = doc.getIntSafe("mal_id", 0),
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images"),
role = doc.getStringSafe("role"),
voiceActor = doc.getListSafe<Document>("voice_actor").map { documentToActor(it) }
)
}
fun documentToScore(doc: Document): Score {
return Score(
percentage = when (val value = doc["percentage"]) {
is Double -> value
is Int -> value.toDouble()
else -> 0.0
},
score = doc.getIntSafe("score", 0),
votes = doc.getIntSafe("votes", 0)
fun documentToActor(doc: Document): Actor {
return Actor(
person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(),
language = doc.getStringSafe("language")
)
}
fun documentToStaff(doc: Document): Staff {
return Staff(
person = doc.get("person", Document::class.java)?.let { documentToIndividual(it) } ?: Individual(),
positions = doc.getListSafe<String>("positions")
fun documentToIndividual(doc: Document): Individual {
return Individual(
malId = doc.getIntSafe("malId", 0),
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images")
)
}
fun documentToExternalLinks(doc: Document): ExternalLinks {
return ExternalLinks(
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name")
)
}
@ -190,19 +197,37 @@ fun documentToStatistics(doc: Document): Statistics {
)
}
fun documentToAiringTime(doc: Document): AiringTime {
return AiringTime(
from = doc.getStringSafe("from"),
to = doc.getStringSafe("to")
)
}
fun documentToThemes(doc: Document): Themes {
return Themes(
endings = doc.getListSafe<String>("endings"),
openings = doc.getListSafe<String>("openings")
openings = doc.getListSafe<String>("openings"),
endings = doc.getListSafe<String>("endings")
)
}
fun documentToVideoPromo(doc: Document): VideoPromo {
return VideoPromo(
embedUrl = doc.getStringSafe("embedUrl"),
url = doc.getStringSafe("url"),
youtubeId = doc.getStringSafe("youtubeId"),
images = doc.get("images", Document::class.java)?.let { documentToImages(it) } ?: Images()
fun documentToAnimeBroadcast(doc: Document): AnimeBroadcast {
return AnimeBroadcast(
day = doc.getStringSafe("day"),
time = doc.getStringSafe("time"),
timezone = doc.getStringSafe("timezone")
)
}
fun documentToScore(doc: Document): Score {
return Score(
percentage = when (val value = doc["percentage"]) {
is Double -> value
is Int -> value.toDouble()
else -> 0.0
},
score = doc.getIntSafe("score", 0),
votes = doc.getIntSafe("votes", 0)
)
}
@ -228,7 +253,7 @@ fun documentToAnimeTopEntity(doc: Document) = AnimeTopEntity(
subtype = doc.getStringSafe("subtype"),
)
fun documentToAnimeLastEpisodeEntity(doc: Document) = LastEpisodeData(
fun documentToAnimeLastEpisodeEntity(doc: Document) = LastEpisodeEntity(
malId = doc.getIntSafe("malId"),
title = doc.getStringSafe("title"),
image = doc.getStringSafe("image"),
@ -290,15 +315,6 @@ fun documentToAnimeDirectoryEntity(doc: Document) = AnimeTypeEntity(
season = doc.getStringSafe("season")
)
fun documentToAnimesEntity(doc: Document) = AnimesEntity(
year = doc.getIntSafe("year"),
slug = doc.getStringSafe("slug"),
name = doc.getStringSafe("name"),
image = doc.getStringSafe("image"),
season = doc.getStringSafe("season")
)
fun documentToAnimesThemeEntity(doc: Document) = Anime(
year = doc.getIntSafe("year"),
slug = doc.getStringSafe("slug"),

@ -1,16 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class AlternativeTitles(
/**
* Title for anime.
*/
val title: String = "",
/**
* Title type for anime.
*/
val type: String = ""
)

@ -4,7 +4,10 @@ import kotlinx.serialization.Serializable
@Serializable
data class Character(
var character: Individual = Individual(),
val malId: Int = 0,
val url: String = "",
val name: String = "",
val images: String = "",
var role: String = "",
var voiceActor: List<Actor> = emptyList()
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeDurationEntity(
var unit: String? = null,
var value: Int? = null
)

@ -0,0 +1,18 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeInfo(
val number: Int? = null,
val seasonNumber: Int? = null,
val relativeNumber: Int? = null,
val airdate: String? = null,
val duration: Int? = null,
val thumbnail: String? = null,
val synopsis: MultipleLanguage? = null,
val titles: MultipleLanguageTitles? = null,
var score: Double? = null,
var filler: Boolean? = false,
var recap: Boolean? = false
)

@ -1,12 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class ImageMediaEntity(
val media: String,
val thumbnail: String,
val width: Int,
val height: Int,
val url: String
)

@ -1,16 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MergedEpisode(
var malId: Int,
var title: String,
var titleJapanese: String,
var titleRomanji: String,
var aired: String,
var score: Float,
var filler: Boolean,
var recap: Boolean,
)

@ -1,52 +1,39 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.bson.Document
@Serializable
data class MoreInfoEntity(
var malId: Int = 0,
val id: String = "",
val id: String? = null,
var malId: Int? = null,
val rank: Int? = null,
var title: String = "",
var poster: String = "",
var cover: String = "",
var genres: List<String> = emptyList(),
var synopsis: String = "",
var episodes: List<MergedEpisode> = emptyList(),
var episodesCount: Int = 0,
var score: String = "",
var staff: List<Staff> = emptyList(),
var characters: List<Character> = emptyList(),
var status: String = "",
var episodes: Int? = null,
var episodeList: List<EpisodeInfo>? = null,
var type: String = "",
val url: String = "",
val promo: VideoPromo? = VideoPromo(),
val duration: String = "",
val rank: Int = 0,
val titles: List<AlternativeTitles> = emptyList(),
val airing: Boolean = false,
val aired: AiringTime = AiringTime(),
val broadcast: AnimeBroadcast = AnimeBroadcast(),
val season: String = "",
val year: Int = 0,
val external: List<ExternalLinks> = emptyList(),
val streaming: List<ExternalLinks> = emptyList(),
val studios: List<Companies> = emptyList(),
val licensors: List<Companies> = emptyList(),
val producers: List<Companies> = emptyList(),
val theme: Themes = Themes(),
val relations: List<Related> = emptyList(),
val stats: Statistics = Statistics(),
val gallery: List<ImageMediaEntity> = emptyList(),
val episodeSource: String = ""
) {
fun toDocument(): Document = Document.parse(Json.encodeToString(this))
companion object {
private val json = Json { ignoreUnknownKeys = true }
fun fromDocument(document: Document): MoreInfoEntity = json.decodeFromString(document.toJson())
}
}
var status: String = "",
var season: SeasonalEntity? = null,
var poster: String = "",
var cover: String? = null,
var duration: EpisodeDurationEntity? = null,
var score: String? = null,
var titles: OtherTitlesEntity? = null,
val studios: List<Companies>? = null,
val producers: List<Companies>? = null,
val licensors: List<Companies>? = null,
val relations: List<Related>? = null,
val promo: VideoPromo? = null,
var tags: MultipleLanguageLists? = null,
var synopsis: MultipleLanguage? = null,
var staff: List<Staff>? = null,
var characters: List<Character>? = null,
val streaming: List<ExternalLinks>? = null,
val urls: List<String>? = null,
val broadcast: AnimeBroadcast? = null,
val external: List<ExternalLinks>? = null,
val stats: Statistics? = null,
val nsfw: Boolean = false,
val ageRating: String? = null,
val aired: AiringTime? = null,
val themes: Themes? = null
)

@ -3,8 +3,7 @@ package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class AnimeSource(
val id: String,
val source: String
)
data class MultipleLanguage(
val es: String? = null,
val en: String? = null
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MultipleLanguageLists(
val es: List<String>? = null,
val en: List<String>? = null
)

@ -0,0 +1,11 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MultipleLanguageTitles(
val es: String? = null,
val en: String? = null,
val jp: String? = null,
val romaji_jp: String? = null,
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class OtherTitlesEntity(
var synonyms: List<String>? = null,
var abbreviatedTitles: List<String>? = null
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class SeasonalEntity(
var station: String? = null,
var year: Int? = null
)

@ -0,0 +1,15 @@
package com.jeluchu.features.anime.models.episodes
import com.jeluchu.core.models.jikan.anime.AnimeData
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeEntity(
val malId: Int = 0,
val title: String?,
val score: String?,
val image: String?,
val day: String?,
val time: String?,
val timezone: String?,
)

@ -4,7 +4,7 @@ import com.jeluchu.core.models.jikan.anime.AnimeData
import kotlinx.serialization.Serializable
@Serializable
data class LastEpisodeData(
data class LastEpisodeEntity(
val malId: Int = 0,
val title: String?,
val score: String?,
@ -14,7 +14,7 @@ data class LastEpisodeData(
val timezone: String?,
) {
companion object {
fun AnimeData.toLastEpisodeData() = LastEpisodeData(
fun AnimeData.toLastEpisodeData() = LastEpisodeEntity(
malId = malId ?: 0,
day = broadcast?.day.orEmpty(),
time = broadcast?.time.orEmpty(),

@ -8,8 +8,8 @@ import com.jeluchu.core.extensions.update
import com.jeluchu.core.messages.ErrorMessages
import com.jeluchu.core.models.ErrorResponse
import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData.Companion.toLastEpisodeData
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity.Companion.toLastEpisodeData
import com.jeluchu.core.models.jikan.search.AnimeSearch
import com.jeluchu.core.utils.BaseUrls
import com.jeluchu.core.utils.Collections
@ -35,8 +35,7 @@ class AnimeService(
private val database: MongoDatabase
) {
private val timers = database.getCollection(Collections.TIMERS)
private val directoryCollection = database.getCollection(Collections.ANIME_DETAILS)
private val lastEpisodesCollection = database.getCollection(Collections.LAST_EPISODES)
private val directoryCollection = database.getCollection(Collections.ANIME_DIRECTORY)
suspend fun getDirectory(call: RoutingCall) = try {
val type = call.request.queryParameters["type"].orEmpty()
@ -116,7 +115,7 @@ class AnimeService(
AnimeSearch.serializer()
)
val animes = mutableListOf<LastEpisodeData>()
val animes = mutableListOf<LastEpisodeEntity>()
val totalPage = response.pagination?.lastPage ?: 0
response.data?.map { it.toLastEpisodeData() }.orEmpty().let { animes.addAll(it) }
@ -130,7 +129,7 @@ class AnimeService(
delay(1000)
}
val documentsToInsert = parseDataToDocuments(animes, LastEpisodeData.serializer())
val documentsToInsert = parseDataToDocuments(animes, LastEpisodeEntity.serializer())
if (documentsToInsert.isNotEmpty()) collection.insertMany(documentsToInsert)
timers.update(timerKey)

@ -8,7 +8,6 @@ import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.core.utils.Collections
import com.jeluchu.core.utils.TimerKey
import com.jeluchu.features.anime.mappers.documentToAnimeDirectoryEntity
import com.jeluchu.features.anime.mappers.documentToAnimeTypeEntity
import com.mongodb.client.MongoCollection
import com.mongodb.client.MongoDatabase
import com.mongodb.client.model.Filters
@ -23,7 +22,7 @@ import org.bson.conversions.Bson
class DirectoryService(
private val database: MongoDatabase,
private val timers: MongoCollection<Document> = database.getCollection(Collections.TIMERS),
private val directory: MongoCollection<Document> = database.getCollection(Collections.ANIME_DETAILS)
private val directory: MongoCollection<Document> = database.getCollection(Collections.ANIME_DIRECTORY)
) {
suspend fun getAnimeByType(call: RoutingCall) {
val param = call.getStringSafeParam("type").uppercase()

@ -5,7 +5,6 @@ import com.jeluchu.core.extensions.getIntSafeQueryParam
import com.jeluchu.core.messages.ErrorMessages
import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.core.utils.Collections
import com.jeluchu.features.anime.mappers.documentToAnimesEntity
import com.jeluchu.features.anime.mappers.documentToAnimesThemeEntity
import com.mongodb.client.MongoDatabase
import io.ktor.http.*

Loading…
Cancel
Save