diff --git a/internal/api/v2/common.go b/internal/api/v2/common.go index 06e2b7e09..8cceeea13 100644 --- a/internal/api/v2/common.go +++ b/internal/api/v2/common.go @@ -3,7 +3,9 @@ package v2 import ( "io" "net/http" + "slices" "strconv" + "strings" "github.com/formancehq/go-libs/api" @@ -12,7 +14,6 @@ import ( "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/time" - "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/go-libs/query" ) @@ -70,11 +71,21 @@ func getPITFilterWithVolumes(r *http.Request) (*ledgercontroller.PITFilterWithVo } return &ledgercontroller.PITFilterWithVolumes{ PITFilter: *pit, - ExpandVolumes: collectionutils.Contains(r.URL.Query()["expand"], "volumes"), - ExpandEffectiveVolumes: collectionutils.Contains(r.URL.Query()["expand"], "effectiveVolumes"), + ExpandVolumes: hasExpandVolumes(r), + ExpandEffectiveVolumes: hasExpandEffectiveVolumes(r), }, nil } +func hasExpandVolumes(r *http.Request) bool { + parts := strings.Split(r.URL.Query().Get("expand"), ",") + return slices.Contains(parts, "volumes") +} + +func hasExpandEffectiveVolumes(r *http.Request) bool { + parts := strings.Split(r.URL.Query().Get("expand"), ",") + return slices.Contains(parts, "effectiveVolumes") +} + func getFiltersForVolumes(r *http.Request) (*ledgercontroller.FiltersForVolumes, error) { pit, err := getPITOOTFilter(r) if err != nil { diff --git a/internal/api/v2/controllers_accounts_read.go b/internal/api/v2/controllers_accounts_read.go index 932782616..22259ab0e 100644 --- a/internal/api/v2/controllers_accounts_read.go +++ b/internal/api/v2/controllers_accounts_read.go @@ -5,7 +5,6 @@ import ( "net/url" "github.com/formancehq/go-libs/api" - "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/platform/postgres" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" @@ -22,10 +21,10 @@ func readAccount(w http.ResponseWriter, r *http.Request) { } query := ledgercontroller.NewGetAccountQuery(param) - if collectionutils.Contains(r.URL.Query()["expand"], "volumes") { + if hasExpandVolumes(r) { query = query.WithExpandVolumes() } - if collectionutils.Contains(r.URL.Query()["expand"], "effectiveVolumes") { + if hasExpandEffectiveVolumes(r) { query = query.WithExpandEffectiveVolumes() } pitFilter, err := getPITFilter(r) diff --git a/internal/api/v2/controllers_transactions_read.go b/internal/api/v2/controllers_transactions_read.go index 39e652ee2..936f20a1d 100644 --- a/internal/api/v2/controllers_transactions_read.go +++ b/internal/api/v2/controllers_transactions_read.go @@ -5,7 +5,6 @@ import ( "strconv" "github.com/formancehq/go-libs/api" - "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/platform/postgres" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" @@ -22,10 +21,10 @@ func readTransaction(w http.ResponseWriter, r *http.Request) { } query := ledgercontroller.NewGetTransactionQuery(int(txId)) - if collectionutils.Contains(r.URL.Query()["expand"], "volumes") { + if hasExpandVolumes(r) { query = query.WithExpandVolumes() } - if collectionutils.Contains(r.URL.Query()["expand"], "effectiveVolumes") { + if hasExpandEffectiveVolumes(r) { query = query.WithExpandEffectiveVolumes() } diff --git a/openapi.yaml b/openapi.yaml index 7dc40921c..5d053c608 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -3228,6 +3228,9 @@ components: V2Transaction: type: object properties: + insertedAt: + type: string + format: date-time timestamp: type: string format: date-time @@ -3249,21 +3252,23 @@ components: revertedAt: type: string format: date-time + preCommitVolumes: + $ref: '#/components/schemas/V2AggregatedVolumes' + postCommitVolumes: + $ref: '#/components/schemas/V2AggregatedVolumes' + preCommitEffectiveVolumes: + $ref: '#/components/schemas/V2AggregatedVolumes' + postCommitEffectiveVolumes: + $ref: '#/components/schemas/V2AggregatedVolumes' required: - postings - timestamp - id - metadata - reverted + - insertedAt V2ExpandedTransaction: - allOf: - - $ref: '#/components/schemas/V2Transaction' - - type: object - properties: - preCommitVolumes: - $ref: '#/components/schemas/V2AggregatedVolumes' - postCommitVolumes: - $ref: '#/components/schemas/V2AggregatedVolumes' + $ref: '#/components/schemas/V2Transaction' V2PostTransaction: type: object required: diff --git a/test/e2e/integration_test.go b/test/e2e/integration_test.go index f5f5b1222..5d407c2bf 100644 --- a/test/e2e/integration_test.go +++ b/test/e2e/integration_test.go @@ -167,15 +167,21 @@ var _ = Context("Ledger integration tests", func() { transactionFromAPI, err := GetTransaction(ctx, testServer.GetValue(), operations.V2GetTransactionRequest{ Ledger: createLedgerRequest.Ledger, ID: tx.ID, + Expand: pointer.For("volumes,effectiveVolumes"), }) Expect(err).To(BeNil()) Expect(&components.V2Transaction{ - Timestamp: transactionFromAPI.Timestamp, - Postings: transactionFromAPI.Postings, - Reference: transactionFromAPI.Reference, - Metadata: transactionFromAPI.Metadata, - ID: transactionFromAPI.ID, - Reverted: transactionFromAPI.Reverted, + InsertedAt: transactionFromAPI.InsertedAt, + Timestamp: transactionFromAPI.Timestamp, + Postings: transactionFromAPI.Postings, + Reference: transactionFromAPI.Reference, + Metadata: transactionFromAPI.Metadata, + ID: transactionFromAPI.ID, + Reverted: transactionFromAPI.Reverted, + PreCommitEffectiveVolumes: transactionFromAPI.PreCommitEffectiveVolumes, + PostCommitEffectiveVolumes: transactionFromAPI.PostCommitEffectiveVolumes, + PreCommitVolumes: transactionFromAPI.PreCommitVolumes, + PostCommitVolumes: transactionFromAPI.PostCommitVolumes, }).To(Equal(tx)) }) })