Skip to content

Commit

Permalink
Fix: Proper usage of call.receive()
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Oct 29, 2024
1 parent 396bc89 commit 7a5f8cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
25 changes: 6 additions & 19 deletions src/main/kotlin/Routings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ import java.util.UUID
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

private val connectionString = System.getenv("MONGO_DB_CONNECTION_STRING") ?: ""
private val connectionString =
"mongodb+srv://mongodb:[email protected]/?retryWrites=true&w=majority&appName=cluster0"

private val serverApi = ServerApi.builder()
.version(ServerApiVersion.V1)
Expand Down Expand Up @@ -212,9 +213,7 @@ fun Application.configureRouting() {

try {

val byteArray = call.receive<ByteArray>()

val checksum = byteArray.decodeToString()
val checksum = call.receive<String>()

if (checksum.isBlank()) {
call.respond(HttpStatusCode.NotAcceptable, "checksum was not set.")
Expand Down Expand Up @@ -335,11 +334,7 @@ fun Application.configureRouting() {

try {

val byteArray = call.receive<ByteArray>()

val filterQueryJson = byteArray.decodeToString()

val filterQuery = FilterQuery.parse(filterQueryJson)
val filterQuery = call.receive<FilterQuery>()

val filter = generateFilter(filterQuery)

Expand Down Expand Up @@ -430,11 +425,7 @@ fun Application.configureRouting() {

try {

val byteArray = call.receive<ByteArray>()

val jsonString = byteArray.decodeToString()

val upload = strictAllFieldsJson.decodeFromString<Upload>(jsonString)
val upload = call.receive<Upload>()

if (upload.userId.isBlank()) {
call.respond(HttpStatusCode.NotAcceptable, "userId was not set.")
Expand Down Expand Up @@ -546,11 +537,7 @@ fun Application.configureRouting() {

try {

val byteArray = call.receive<ByteArray>()

val jsonString = byteArray.decodeToString()

val failedGenReport = strictAllFieldsJson.decodeFromString<FailedGenReport>(jsonString)
val failedGenReport = call.receive<FailedGenReport>()

if (failedGenReport.userId.isBlank()) {
call.respond(HttpStatusCode.NotAcceptable, "userId was not set.")
Expand Down
10 changes: 1 addition & 9 deletions src/main/kotlin/model/filter/FilterQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package model.filter

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json

@Serializable
data class FilterQuery(
Expand All @@ -37,11 +36,4 @@ data class FilterQuery(
*/
val rules: List<List<FilterRule>>

) {

companion object {

fun parse(json: String): FilterQuery =
Json.decodeFromString<FilterQuery>(json)
}
}
)

0 comments on commit 7a5f8cf

Please sign in to comment.