Skip to content

Commit

Permalink
fix: restore api response for /data endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter committed Jul 23, 2024
1 parent 706ef0c commit afcf37b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import reactor.kotlin.core.publisher.toFlux
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.*
import kotlin.jvm.optionals.getOrElse


@RestController
Expand Down Expand Up @@ -114,25 +115,41 @@ class ReportCalculationController(
val fileContent = reportingStorage
.fetchData(DomainReference(id = calculationId))

val prefix = """
{
"calculation": "$calculationId",
"data":
""".trimIndent().toByteArray()
val prefixBuffer = DefaultDataBufferFactory().allocateBuffer(prefix.size)
prefixBuffer.write(prefix)

val suffix = """
}
""".trimIndent().toByteArray()
val suffixBuffer = DefaultDataBufferFactory().allocateBuffer(suffix.size)
suffixBuffer.write(suffix)

return@flatMap Flux.concat(
Flux.just(prefixBuffer),
fileContent,
Flux.just(suffixBuffer),
)
reportingStorage.fetchCalculation(DomainReference(calculationId))
.toFlux()
.flatMap {

val calculation = it.getOrElse {
return@flatMap Flux.error { NotFoundException("No data available") }
}

val prefix = """
{
"_id": "${calculationId}_data.json",
"report": {
"id": "${calculation.report.id}"
},
"calculation": {
"id": "$calculationId"
},
"dataHash": "${calculation.attachments["data.json"]?.digest}",
"data":
""".trimIndent().toByteArray()
val prefixBuffer = DefaultDataBufferFactory().allocateBuffer(prefix.size)
prefixBuffer.write(prefix)

val suffix = """
}
""".trimIndent().toByteArray()
val suffixBuffer = DefaultDataBufferFactory().allocateBuffer(suffix.size)
suffixBuffer.write(suffix)

Flux.concat(
Flux.just(prefixBuffer),
fileContent,
Flux.just(suffixBuffer),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: the report calculation data endpoint persist to database
When the client calls GET /v1/reporting/report-calculation/ReportCalculation:1/data
Then the client receives an json object
Then the client receives status code of 200
Then the client receives value ReportCalculation:1_data.json for property id
Then the client receives value ReportCalculation:1_data.json for property _id

# ReportCalculation not available
Scenario: client makes call to GET /reporting/report-calculation/ReportCalculation:42/data and receives NotFound
Expand Down

0 comments on commit afcf37b

Please sign in to comment.