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 Aug 7, 2024
1 parent afcf37b commit cb1036c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.aamdigital.aambackendservice.reporting.report.core.ReportingStorage
import com.aamdigital.aambackendservice.reporting.reportcalculation.core.CreateReportCalculationRequest
import com.aamdigital.aambackendservice.reporting.reportcalculation.core.CreateReportCalculationResult
import com.aamdigital.aambackendservice.reporting.reportcalculation.core.CreateReportCalculationUseCase
import com.aamdigital.aambackendservice.reporting.reportcalculation.dto.ReportCalculationData
import com.aamdigital.aambackendservice.reporting.reportcalculation.dto.ReportCalculationDto
import com.aamdigital.aambackendservice.reporting.storage.DefaultReportStorage
import org.springframework.core.io.buffer.DataBuffer
Expand Down Expand Up @@ -125,7 +126,7 @@ class ReportCalculationController(

val prefix = """
{
"_id": "${calculationId}_data.json",
"id": "${calculationId}_data.json",
"report": {
"id": "${calculation.report.id}"
},
Expand Down Expand Up @@ -168,6 +169,15 @@ class ReportCalculationController(
startDate = it.calculationStarted,
endDate = it.calculationCompleted,
args = it.args,
attachments = it.attachments,
data = toReportCalculationData(it),
)

private fun toReportCalculationData(it: ReportCalculation): ReportCalculationData? {
val attachment = it.attachments["data.json"] ?: return null
return ReportCalculationData(
contentType = attachment.contentType,
hash = attachment.digest,
length = attachment.length
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aamdigital.aambackendservice.reporting.reportcalculation.dto

import com.aamdigital.aambackendservice.couchdb.dto.AttachmentMetaData
import com.aamdigital.aambackendservice.domain.DomainReference
import com.aamdigital.aambackendservice.reporting.domain.ReportCalculationStatus

Expand All @@ -14,7 +13,13 @@ data class ReportCalculationDto(
var startDate: String? = null,
var endDate: String? = null,
var args: Map<String, String>,
var attachments: Map<String, AttachmentMetaData> = emptyMap(),
var data: ReportCalculationData?,
)

data class ReportCalculationData(
val contentType: String,
val hash: String,
val length: Number,
)

/**
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
40 changes: 29 additions & 11 deletions docs/api-specs/reporting-api-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,32 @@ components:
id:
type: string
format: uuid
start_date:
report:
type: object
properties:
id:
type: string
format: uuid
status:
type: string
description: Current status of the run
enum:
- PENDING
- RUNNING
- FINISHED_SUCCESS
- FINISHED_ERROR
startDate:
type: string
description: The Date, the calculation starts processing the query
example: date
end_date:
endDate:
type: string
description: The Date, the calculation finished processing and the data is available
example: date
nullable: true
params:
args:
type: object
description: Input arguments will be injected into the sql query
properties:
from:
type: string
Expand All @@ -502,14 +519,15 @@ components:
description: optional end date filtering data included in the report. If no date is given here, all data (possibly filtered by the "from" date) is included. The field considered for date filtering are defined in each report's query specifically.
format: date
nullable: true
status:
type: string
description: Current status of the run
enum:
- PENDING
- RUNNING
- FINISHED_SUCCESS
- FINISHED_ERROR
data:
type: object
properties:
contentType:
type: string
hash:
type: string
length:
type: number

ReportData:
type: object
Expand Down

0 comments on commit cb1036c

Please sign in to comment.