backend module update

This commit is contained in:
John O'Reilly 2020-05-16 22:21:45 +01:00
parent 070f438e19
commit c473561dfb

View file

@ -3,19 +3,18 @@ import io.ktor.routing.*
import io.ktor.serialization.* import io.ktor.serialization.*
import io.ktor.server.engine.* import io.ktor.server.engine.*
import io.ktor.server.netty.* import io.ktor.server.netty.*
import com.surrus.common.repository.PeopleInSpaceRepository
import com.surrus.common.remote.PeopleInSpaceApi import com.surrus.common.remote.PeopleInSpaceApi
import com.surrus.common.remote.AstroResult
import com.surrus.common.remote.Assignment
import io.ktor.application.call import io.ktor.application.call
import io.ktor.application.install import io.ktor.application.install
import io.ktor.features.ContentNegotiation import io.ktor.features.ContentNegotiation
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.http.content.resources import io.ktor.http.content.resources
import io.ktor.http.content.static import io.ktor.http.content.static
import kotlinx.coroutines.flow.collect
fun main() { fun main() {
val repository = PeopleInSpaceRepository()
val peopleInSpaceApi = PeopleInSpaceApi() val peopleInSpaceApi = PeopleInSpaceApi()
embeddedServer(Netty, 9090) { embeddedServer(Netty, 9090) {
@ -36,17 +35,19 @@ fun main() {
resources("") resources("")
} }
get("/people") {
repository.fetchPeopleAsFlow()?.collect {
call.respond(it)
}
}
get("/astros.json") { get("/astros.json") {
val result = peopleInSpaceApi.fetchPeople() val result = peopleInSpaceApi.fetchPeople()
call.respond(result) call.respond(result)
} }
get("/astros_local.json") {
val result = AstroResult("success", 3,
listOf(Assignment("ISS", "Chris Cassidy"),
Assignment("ISS", "Anatoly Ivanishin"),
Assignment("ISS", "Ivan Vagner")))
call.respond(result)
}
} }
}.start(wait = true) }.start(wait = true)
} }