|
|
|
@ -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.and(
|
|
|
|
|
Filters.or(
|
|
|
|
|
Filters.`in`("tags.es", tags),
|
|
|
|
|
Filters.`in`("tags.en", tags),
|
|
|
|
|
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()
|
|
|
|
|