mirror of https://github.com/aruppi/aruppi-api
Fixed Simple Anime Entity and move tags to suggestion endpoint
This commit is contained in:
parent
b0fd2e84ad
commit
6931ff7084
|
@ -3,9 +3,7 @@ package com.jeluchu.core.models
|
|||
import com.jeluchu.core.extensions.getDocumentSafe
|
||||
import com.jeluchu.core.extensions.getIntSafe
|
||||
import com.jeluchu.core.extensions.getStringSafe
|
||||
import com.jeluchu.features.anime.mappers.documentToMultipleLanguageLists
|
||||
import com.jeluchu.features.anime.models.anime.MultipleLanguageLists
|
||||
import com.jeluchu.features.anime.models.tags.TagsAnimeEntity
|
||||
import com.jeluchu.core.utils.SeasonCalendar
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.bson.Document
|
||||
|
||||
|
@ -15,13 +13,26 @@ data class SimpleAnimeEntity(
|
|||
val type: String,
|
||||
val title: String,
|
||||
val image: String,
|
||||
val score: String
|
||||
)
|
||||
val score: String,
|
||||
val season: SeasonInfo
|
||||
) {
|
||||
@Serializable
|
||||
data class SeasonInfo(
|
||||
val year: Int? = null,
|
||||
val station: String? = null
|
||||
)
|
||||
}
|
||||
|
||||
fun documentToSimpleAnimeEntity(doc: Document) = SimpleAnimeEntity(
|
||||
malId = doc.getIntSafe("malId"),
|
||||
title = doc.getStringSafe("title"),
|
||||
type = doc.getStringSafe("type"),
|
||||
score = doc.getStringSafe("score"),
|
||||
image = doc.getStringSafe("poster")
|
||||
image = doc.getStringSafe("poster"),
|
||||
season = doc.getDocumentSafe("season")?.let { documentToSeasonInfo(it) } ?: SimpleAnimeEntity.SeasonInfo(),
|
||||
)
|
||||
|
||||
fun documentToSeasonInfo(doc: Document) = SimpleAnimeEntity.SeasonInfo(
|
||||
year = doc.getIntSafe("year"),
|
||||
station = doc.getStringSafe("station")
|
||||
)
|
|
@ -74,6 +74,7 @@ object Routes {
|
|||
const val SEASON_PARAMS = "/{year}/{season}"
|
||||
const val DAY = "/{day}"
|
||||
const val THEMES = "/themes"
|
||||
const val SUGGESTIONS = "/suggestions"
|
||||
const val YEAR_INDEX = "/yearIndex"
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,12 @@ fun Route.animeEndpoints(
|
|||
) = route(Routes.ANIME) {
|
||||
getToJson { service.getAnimeByType(call) }
|
||||
getToJson(Routes.ID) { service.getAnimeByMalId(call) }
|
||||
getToJson(Routes.TAGS) { tagsService.getAnimeByAnyTag(call) }
|
||||
getToJson(Routes.LAST_EPISODES) { service.getLastEpisodes(call) }
|
||||
|
||||
route(Routes.SUGGESTIONS) {
|
||||
getToJson { tagsService.getAnimeByAnyTag(call) }
|
||||
}
|
||||
|
||||
route(Routes.SEASON) {
|
||||
getToJson { seasonService.getAnimeBySeason(call) }
|
||||
getToJson(Routes.YEAR_INDEX) { seasonService.getYearsAndSeasons(call) }
|
||||
|
|
|
@ -25,7 +25,7 @@ class SeasonService(
|
|||
) {
|
||||
suspend fun getAnimeBySeason(call: RoutingCall) {
|
||||
val year = call.request.queryParameters["year"]?.toInt() ?: SeasonCalendar.currentYear
|
||||
val station = parseSeasons(call.request.queryParameters["season"] ?: SeasonCalendar.currentSeason.name)
|
||||
val station = parseSeasons(call.request.queryParameters["station"] ?: SeasonCalendar.currentSeason.name)
|
||||
?: SeasonCalendar.currentSeason
|
||||
|
||||
val query = directory.find(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jeluchu.features.anime.services
|
||||
|
||||
import com.jeluchu.core.enums.AnimeStatusTypes
|
||||
import com.jeluchu.core.models.documentToSimpleAnimeEntity
|
||||
import com.jeluchu.core.utils.Collections
|
||||
import com.mongodb.client.MongoCollection
|
||||
|
@ -17,23 +18,26 @@ class TagsService(
|
|||
private val directory: MongoCollection<Document> = database.getCollection(Collections.ANIME_DIRECTORY)
|
||||
) {
|
||||
suspend fun getAnimeByAnyTag(call: RoutingCall) {
|
||||
val tagsParam = call.request.queryParameters["tags"].orEmpty()
|
||||
val tags = call.request.queryParameters["tags"].orEmpty()
|
||||
|
||||
val tags = if (tagsParam.isNotEmpty()) {
|
||||
tagsParam.split(",").map { it.trim() }
|
||||
val tagsList = if (tags.isNotEmpty()) {
|
||||
tags.split(",").map { it.trim() }
|
||||
} else emptyList()
|
||||
|
||||
if (tags.isEmpty()) {
|
||||
if (tagsList.isEmpty()) {
|
||||
call.respond(HttpStatusCode.BadRequest, "No tags provided")
|
||||
return
|
||||
}
|
||||
|
||||
val query = directory.find(
|
||||
Filters.or(
|
||||
Filters.`in`("tags.es", tags),
|
||||
Filters.`in`("tags.en", tags),
|
||||
Filters.and(
|
||||
Filters.or(
|
||||
Filters.`in`("tags.es", tagsList),
|
||||
Filters.`in`("tags.en", tagsList)
|
||||
),
|
||||
Filters.`in`("status", listOf(AnimeStatusTypes.FINISHED, AnimeStatusTypes.ONGOING)),
|
||||
Filters.ne("type", "MUSIC"),
|
||||
Filters.ne("type", "PV"),
|
||||
Filters.ne("type", "PV")
|
||||
)
|
||||
)
|
||||
.toList()
|
||||
|
|
Loading…
Reference in New Issue