https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

DMITRY.

04/02/2021, 9:40 PM
Copy code
val aggregation = Aggregation.newAggregation(Aggregation.sample(1))
        val commit = mongoOperations.aggregate(aggregation, "commit", Commit::class.java).uniqueMappedResult
        commit?.message
            ?.let { return ResponseEntity<String>(commit.message, HttpStatus.OK) }
            ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Unable to find commit")
Does that look like the Kotlin way?
e

ephemient

04/02/2021, 10:05 PM
the
Commit::class.java
bit looks the least Kotlin-like
understandable if that's the API you have to deal with, but a wrapper like
Copy code
inline fun <reified O> MongoOperations.aggregate(aggretation: Aggregation, name: String): AggregationResults<O> =
    aggregate(aggregation, name, O::class.java)
would let you write
.aggregate<Commit>(aggregation, "commit")
in Kotlin
although if the API is Java... might run into annoyances like https://youtrack.jetbrains.com/issue/KT-11968
8 Views