Skip to content

Commit

Permalink
feat: update for Ledger v2 (#468)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Wacheux <[email protected]>
Co-authored-by: Maxence Maireaux <[email protected]>
Co-authored-by: Brieuc Caillot <[email protected]>
  • Loading branch information
4 people committed Sep 20, 2023
1 parent 7ad4777 commit 1641c3c
Show file tree
Hide file tree
Showing 3,383 changed files with 220,367 additions and 24,834 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ linters:
enable:
- gofmt
- goimports
- unused
17 changes: 14 additions & 3 deletions components/fctl/cmd/ledger/accounts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package accounts
import (
"fmt"

internal "github.com/formancehq/fctl/cmd/ledger/internal"
"github.com/formancehq/fctl/cmd/ledger/internal"
fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
Expand Down Expand Up @@ -74,9 +74,20 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
return nil, err
}

body := make([]map[string]map[string]any, 0)
for key, value := range metadata {
body = append(body, map[string]map[string]any{
"$match": {
"metadata[" + key + "]": value,
},
})
}

request := operations.ListAccountsRequest{
Ledger: fctl.GetString(cmd, internal.LedgerFlag),
Metadata: metadata,
Ledger: fctl.GetString(cmd, internal.LedgerFlag),
RequestBody: map[string]interface{}{
"$and": body,
},
}
rsp, err := ledgerClient.Ledger.ListAccounts(cmd.Context(), request)
if err != nil {
Expand Down
113 changes: 0 additions & 113 deletions components/fctl/cmd/ledger/balances.go

This file was deleted.

10 changes: 5 additions & 5 deletions components/fctl/cmd/ledger/internal/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

// Copy from SDK
type TransactionsCursorResponseCursor struct {
Data []ExpandedTransaction `json:"data"`
HasMore bool `json:"hasMore"`
Next *string `json:"next,omitempty"`
PageSize int64 `json:"pageSize"`
Previous *string `json:"previous,omitempty"`
Data []shared.ExpandedTransaction `json:"data"`
HasMore bool `json:"hasMore"`
Next *string `json:"next,omitempty"`
PageSize int64 `json:"pageSize"`
Previous *string `json:"previous,omitempty"`
}

// Copy from SDK
Expand Down
12 changes: 6 additions & 6 deletions components/fctl/cmd/ledger/internal/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func printCommonInformation(
out io.Writer,
txID int64,
reference string,
postings []*shared.Posting,
postings []shared.Posting,
timestamp time.Time,
) error {
fctl.Section.WithWriter(out).Println("Information")
Expand Down Expand Up @@ -53,11 +53,11 @@ func printCommonInformation(
return nil
}

func PrintExpandedTransaction(out io.Writer, transaction ExpandedTransaction) error {
func PrintExpandedTransaction(out io.Writer, transaction shared.ExpandedTransaction) error {

if err := printCommonInformation(
out,
transaction.Txid,
transaction.ID,
*transaction.Reference,
transaction.Postings,
transaction.Timestamp,
Expand Down Expand Up @@ -96,11 +96,11 @@ func PrintExpandedTransaction(out io.Writer, transaction ExpandedTransaction) er
return nil
}

func PrintTransaction(out io.Writer, transaction Transaction) error {
func PrintTransaction(out io.Writer, transaction shared.Transaction) error {

if err := printCommonInformation(
out,
transaction.Txid,
transaction.ID,
*transaction.Reference,
transaction.Postings,
transaction.Timestamp,
Expand All @@ -113,7 +113,7 @@ func PrintTransaction(out io.Writer, transaction Transaction) error {
}
return nil
}
func PrintMetadata(out io.Writer, metadata Metadata) error {
func PrintMetadata(out io.Writer, metadata map[string]string) error {
fctl.Section.WithWriter(out).Println("Metadata")
if len(metadata) == 0 {
fmt.Println("No metadata.")
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/ledger/internal/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type RevertTransactionResponseData struct {
Data Transaction `json:"data"`
Data shared.Transaction `json:"data"`
}
type RevertTransactionResponse struct {
ContentType string
Expand All @@ -31,7 +31,7 @@ func RevertTransaction(client *formance.Formance, ctx context.Context, baseURL s
field := reflect.ValueOf(client).Elem().FieldByName("_securityClient")
httpClient := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface().(formance.HTTPClient)

url, err := utils.GenerateURL(ctx, baseURL, "/api/ledger/{ledger}/transactions/{txid}/revert", request, nil)
url, err := utils.GenerateURL(ctx, baseURL, "/api/ledger/{ledger}/transactions/{id}/revert", request, nil)
if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/ledger/internal/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// GetTransactionResponse - OK
type GetTransactionResponseData struct {
Data ExpandedTransaction `json:"data"`
Data shared.ExpandedTransaction `json:"data"`
}

type GetTransactionResponse struct {
Expand All @@ -34,7 +34,7 @@ func GetTransaction(client *formance.Formance, ctx context.Context, baseURL stri
field := reflect.ValueOf(client).Elem().FieldByName("_securityClient")
httpClient := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface().(formance.HTTPClient)

url, err := utils.GenerateURL(ctx, baseURL, "/api/ledger/{ledger}/transactions/{txid}", request, nil)
url, err := utils.GenerateURL(ctx, baseURL, "/api/ledger/{ledger}/transactions/{id}", request, nil)
if err != nil {
return nil, fmt.Errorf("error generating URL: %w", err)
}
Expand Down
Loading

0 comments on commit 1641c3c

Please sign in to comment.