A hopeful fix (again)
authorTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 6 Feb 2022 22:46:40 +0000 (17:46 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Sun, 6 Feb 2022 22:46:40 +0000 (17:46 -0500)
src/jvmMain/kotlin/starshipfights/auth/providers.kt
src/jvmMain/kotlin/starshipfights/data/data_connection.kt
src/jvmMain/kotlin/starshipfights/data/data_documents.kt

index abd3eb7aff285e376fca25b461ab48eca94f75cb..6251422239b721df15183f31305e5e23a4b60991 100644 (file)
@@ -12,9 +12,10 @@ import io.ktor.routing.*
 import io.ktor.sessions.*
 import io.ktor.util.*
 import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.singleOrNull
 import kotlinx.coroutines.launch
 import kotlinx.html.*
-import org.litote.kmongo.eq
 import starshipfights.CurrentConfiguration
 import starshipfights.data.Id
 import starshipfights.data.admiralty.Admiral
@@ -196,7 +197,9 @@ object TestAuthProvider : AuthProvider {
                                        val userAgent = request.userAgent()
                                        if (userAgent != null && credentials.name.isValidUsername() && credentials.password == TEST_PASSWORD) {
                                                sfLogger.info("Attempting to find user ${credentials.name}")
-                                               val user = User.locate(User::username eq credentials.name)
+                                               // TODO find out why java mongodb driver is such a piece of shit
+                                               //val user = User.locate(User::username eq credentials.name)
+                                               val user = User.all().filter { it.username == credentials.name }.singleOrNull()
                                                        ?: User(username = credentials.name).also {
                                                                sfLogger.info("Attempting to add user with name ${credentials.name}")
                                                                User.put(it)
index 7cc0abc8d5b815de7cf725c913c3cf371b4019a8..b6cf384f8f0e20b54190a121b4d03ce4bda6c9db 100644 (file)
@@ -1,11 +1,5 @@
 package starshipfights.data
 
-import com.mongodb.ConnectionString
-import com.mongodb.MongoClientSettings
-import com.mongodb.event.CommandFailedEvent
-import com.mongodb.event.CommandListener
-import com.mongodb.event.CommandStartedEvent
-import com.mongodb.event.CommandSucceededEvent
 import de.flapdoodle.embed.mongo.MongodExecutable
 import de.flapdoodle.embed.mongo.MongodStarter
 import de.flapdoodle.embed.mongo.config.MongoCmdOptions
@@ -26,7 +20,6 @@ import org.litote.kmongo.serialization.registerSerializer
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import starshipfights.game.MomentSerializer
-import starshipfights.sfLogger
 import java.io.File
 import java.net.ServerSocket
 import kotlin.system.exitProcess
@@ -101,26 +94,6 @@ object ConnectionHolder {
                registerSerializer(MomentSerializer)
                
                databaseName = db
-               clientDeferred.complete(
-                       KMongo.createClient(
-                               MongoClientSettings
-                                       .builder()
-                                       .applyConnectionString(ConnectionString(conn.createUrl()))
-                                       .addCommandListener(object : CommandListener {
-                                               override fun commandStarted(event: CommandStartedEvent) {
-                                                       sfLogger.info("Started Mongo command ${event.commandName}")
-                                               }
-                                               
-                                               override fun commandSucceeded(event: CommandSucceededEvent) {
-                                                       sfLogger.info("Succeeded Mongo command ${event.commandName}")
-                                               }
-                                               
-                                               override fun commandFailed(event: CommandFailedEvent) {
-                                                       sfLogger.info("Failed Mongo command ${event.commandName}")
-                                               }
-                                       })
-                                       .build()
-                       ).coroutine
-               )
+               clientDeferred.complete(KMongo.createClient(conn.createUrl()).coroutine)
        }
 }
index 096517c9036fb06705fe8495e3266b21f8e3ce2d..2be671bf3e02403d0ff3c5474fcbb4b5a378f4bb 100644 (file)
@@ -43,6 +43,7 @@ interface DocumentTable<T : DataDocument<T>> {
        suspend fun put(doc: T)
        suspend fun get(id: Id<T>): T?
        suspend fun del(id: Id<T>)
+       suspend fun all(): Flow<T>
        
        suspend fun select(bson: Bson): Flow<T>
        suspend fun locate(bson: Bson): T?
@@ -101,6 +102,10 @@ private class DocumentTableImpl<T : DataDocument<T>>(val kclass: KClass<T>, priv
                collection().deleteOneById(id)
        }
        
+       override suspend fun all(): Flow<T> {
+               return collection().find().toFlow()
+       }
+       
        override suspend fun select(bson: Bson): Flow<T> {
                return collection().find(bson).toFlow()
        }