mirror of https://github.com/aruppi/aruppi-api
Compare commits
2 Commits
93cf3816d6
...
d7ca2965d2
Author | SHA1 | Date |
---|---|---|
![]() |
d7ca2965d2 | |
![]() |
5e4392f861 |
|
@ -4,6 +4,7 @@ import com.jeluchu.features.anime.routes.animeEndpoints
|
|||
import com.jeluchu.features.anitakume.routes.anitakumeEndpoints
|
||||
import com.jeluchu.features.gallery.routes.galleryEndpoints
|
||||
import com.jeluchu.features.news.routes.newsEndpoints
|
||||
import com.jeluchu.features.radiostations.routes.radioStationsEndpoints
|
||||
import com.jeluchu.features.rankings.routes.rankingsEndpoints
|
||||
import com.jeluchu.features.schedule.routes.scheduleEndpoints
|
||||
import com.jeluchu.features.themes.routes.themesEndpoints
|
||||
|
@ -23,5 +24,6 @@ fun Application.initRoutes(
|
|||
rankingsEndpoints(mongoDatabase)
|
||||
scheduleEndpoints(mongoDatabase)
|
||||
anitakumeEndpoints(mongoDatabase)
|
||||
radioStationsEndpoints(mongoDatabase)
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@ object Routes {
|
|||
const val SEARCH = "/search"
|
||||
const val GALLERY = "/gallery"
|
||||
const val SCHEDULE = "/schedule"
|
||||
const val RADIO_STATIONS = "/radio"
|
||||
const val LAST_POST = "/lastPosts"
|
||||
const val DIRECTORY = "/directory"
|
||||
const val ANITAKUME = "/anitakume"
|
||||
|
@ -75,6 +76,7 @@ object Routes {
|
|||
object TimerKey {
|
||||
const val KEY = "key"
|
||||
const val SCHEDULE = "schedule"
|
||||
const val RADIO = "radio_station"
|
||||
const val LAST_UPDATED = "lastUpdated"
|
||||
const val ANIME_TYPE = "anime_"
|
||||
const val THEMES = "themes_"
|
||||
|
@ -88,6 +90,7 @@ object Collections {
|
|||
const val NEWS_EN = "news_en"
|
||||
const val SCHEDULES = "schedule"
|
||||
const val ANITAKUME = "anitakume"
|
||||
const val RADIO = "radio_stations"
|
||||
const val ANIME_THEMES = "anime_themes"
|
||||
const val ARTISTS_INDEX = "artists_index"
|
||||
const val LAST_EPISODES = "last_episodes"
|
||||
|
|
|
@ -53,7 +53,7 @@ class AnitakumeService(
|
|||
.find()
|
||||
.toList()
|
||||
|
||||
val elements = animes.map { documentToNewsEntity(it) }
|
||||
val elements = animes.map { documentToAnitakumeEntity(it) }
|
||||
call.respond(HttpStatusCode.OK, Json.encodeToString(elements))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package com.jeluchu.features.news.mappers
|
||||
|
||||
import com.jeluchu.core.extensions.getBooleanSafe
|
||||
import com.jeluchu.core.extensions.getDocumentSafe
|
||||
import com.jeluchu.core.extensions.getFloatSafe
|
||||
import com.jeluchu.core.extensions.getIntSafe
|
||||
import com.jeluchu.core.extensions.getListSafe
|
||||
import com.jeluchu.core.extensions.getStringSafe
|
||||
import com.jeluchu.core.extensions.parseRssDate
|
||||
import com.jeluchu.features.anime.mappers.documentToVideoPromo
|
||||
import com.jeluchu.features.anime.models.anime.VideoPromo
|
||||
import com.jeluchu.features.news.models.NewEntity
|
||||
import com.prof18.rssparser.model.RssChannel
|
||||
import org.bson.Document
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.jeluchu.features.radiostations.mappers
|
||||
|
||||
import com.jeluchu.core.extensions.getStringSafe
|
||||
import com.jeluchu.features.radiostations.models.RadioStationEntity
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.bson.Document
|
||||
|
||||
fun documentToRadioStation(doc: Document) = RadioStationEntity(
|
||||
name = doc.getStringSafe("name"),
|
||||
image = doc.getStringSafe("image"),
|
||||
genre = doc.getStringSafe("genre"),
|
||||
stream = doc.getStringSafe("stream"),
|
||||
website = doc.getStringSafe("website")
|
||||
)
|
||||
|
||||
fun List<Document>.documentStationsMapper(): String {
|
||||
val directory = map { documentToRadioStation(it) }
|
||||
return Json.encodeToString(directory)
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.jeluchu.features.radiostations.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class RadioStationEntity(
|
||||
val name: String = "",
|
||||
val image: String = "",
|
||||
val genre: String = "",
|
||||
val stream: String = "",
|
||||
val website: String = ""
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
package com.jeluchu.features.radiostations.routes
|
||||
|
||||
import com.jeluchu.core.extensions.getToJson
|
||||
import com.jeluchu.core.utils.Routes
|
||||
import com.jeluchu.features.radiostations.services.RadioStationsService
|
||||
import com.mongodb.client.MongoDatabase
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Route.radioStationsEndpoints(
|
||||
mongoDatabase: MongoDatabase,
|
||||
service: RadioStationsService = RadioStationsService(mongoDatabase)
|
||||
) = route(Routes.RADIO_STATIONS) {
|
||||
getToJson { service.getStations(call) }
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.jeluchu.features.radiostations.services
|
||||
|
||||
import com.jeluchu.core.utils.Collections
|
||||
import com.jeluchu.features.radiostations.mappers.documentStationsMapper
|
||||
import com.mongodb.client.MongoDatabase
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
class RadioStationsService(
|
||||
database: MongoDatabase
|
||||
) {
|
||||
private val radioStations = database.getCollection(Collections.RADIO)
|
||||
|
||||
suspend fun getStations(call: RoutingCall) {
|
||||
val elements = radioStations.find().toList()
|
||||
call.respond(HttpStatusCode.OK, elements.documentStationsMapper())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue