add send message
This commit is contained in:
+10
@@ -5,6 +5,7 @@ import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
import ru.shadowsparky.backend.data.EnvFetcher
|
||||
import ru.shadowsparky.backend.domain.JwtInfo
|
||||
import ru.shadowsparky.domain.AppConfig
|
||||
|
||||
@Module
|
||||
@ComponentScan
|
||||
@@ -20,4 +21,13 @@ class BackendModule {
|
||||
"wear"
|
||||
)
|
||||
}
|
||||
|
||||
@Single
|
||||
fun provideAppConfig(): AppConfig {
|
||||
return object : AppConfig {
|
||||
override val debug = true
|
||||
override val appId = "ru.shadowsparky.gigawear.backend"
|
||||
override val backend = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package ru.shadowsparky.gigawear.backend
|
||||
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.routing
|
||||
import org.koin.core.annotation.KoinApplication
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.plugin.module.dsl.startKoin
|
||||
import ru.shadowsparky.gigawear.backend.presentation.setupChat
|
||||
import ru.shadowsparky.koin
|
||||
|
||||
@KoinApplication
|
||||
object GigaWearApp
|
||||
@@ -18,10 +22,9 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
fun Application.module() {
|
||||
val koin = object : KoinComponent {}
|
||||
this.routing {
|
||||
get("health") {
|
||||
this.call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
install(ContentNegotiation) { json(koin.get()) }
|
||||
routing {
|
||||
get("health") { this.call.respond(HttpStatusCode.OK) }
|
||||
setupChat(koin.get(), koin.get())
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package ru.shadowsparky.gigawear.backend.presentation
|
||||
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.post
|
||||
import ru.shadowsparky.chat.backend.domain.ProcessUserMessageUseCase
|
||||
import ru.shadowsparky.chat.domain.Message
|
||||
|
||||
private const val MOCK_USER_ID = -1L
|
||||
|
||||
fun Routing.setupChat(useCase: ProcessUserMessageUseCase) {
|
||||
post("chat") {
|
||||
val message = call.receive<Message>().copy(timestamp = System.currentTimeMillis())
|
||||
call.respond(useCase.execute(message, MOCK_USER_ID))
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -32,9 +32,7 @@ fun Route.setupChat(
|
||||
val userId = call.obtainUserId()
|
||||
val info = call.receive<Message>()
|
||||
if (info.role != ChatRoles.USER) throw BadRequestException("invalid role")
|
||||
val repository = chatRepositoryFactory.create(userId)
|
||||
repository.send(info)
|
||||
val response = processUserMessageUseCase.execute(userId)
|
||||
val response = processUserMessageUseCase.execute(info, userId)
|
||||
remoteEventHandler.notify(RemoteEvent.OnChatUpdate(userId))
|
||||
call.respond(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user