-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
What Adds a new GET /payments endpoint for fetching the ingested payments. Why New endpoint.
- Loading branch information
1 parent
f41bed0
commit 6be7be6
Showing
17 changed files
with
993 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package data | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stellar/wallet-backend/internal/db" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func InsertTestPayments(t *testing.T, ctx context.Context, payments []Payment, connectionPool db.ConnectionPool) { | ||
t.Helper() | ||
|
||
const query = `INSERT INTO ingest_payments (operation_id, operation_type, transaction_id, transaction_hash, from_address, to_address, src_asset_code, src_asset_issuer, src_amount, dest_asset_code, dest_asset_issuer, dest_amount, created_at, memo) VALUES (:operation_id, :operation_type, :transaction_id, :transaction_hash, :from_address, :to_address, :src_asset_code, :src_asset_issuer, :src_amount, :dest_asset_code, :dest_asset_issuer, :dest_amount, :created_at, :memo);` | ||
_, err := connectionPool.NamedExecContext(ctx, query, payments) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package data | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jmoiron/sqlx" | ||
"github.com/stellar/wallet-backend/internal/db" | ||
) | ||
|
||
type SortOrder string | ||
|
||
const ( | ||
ASC SortOrder = "ASC" | ||
DESC SortOrder = "DESC" | ||
) | ||
|
||
func (o SortOrder) IsValid() bool { | ||
return o == ASC || o == DESC | ||
} | ||
|
||
// PrepareNamedQuery prepares the given query replacing the named parameters with Postgres' bindvars. | ||
// It returns an SQL Injection-safe query and the arguments array to be used alongside it. | ||
func PrepareNamedQuery(ctx context.Context, connectionPool db.ConnectionPool, namedQuery string, argsMap map[string]interface{}) (string, []interface{}, error) { | ||
query, args, err := sqlx.Named(namedQuery, argsMap) | ||
if err != nil { | ||
return "", nil, fmt.Errorf("replacing attributes with bindvars: %w", err) | ||
} | ||
query, args, err = sqlx.In(query, args...) | ||
if err != nil { | ||
return "", nil, fmt.Errorf("expanding slice arguments: %w", err) | ||
} | ||
query = connectionPool.Rebind(query) | ||
|
||
return query, args, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package entities | ||
|
||
type PaginationLinks struct { | ||
Self string `json:"self"` | ||
Prev string `json:"next"` | ||
Next string `json:"prev"` | ||
} | ||
|
||
type Pagination struct { | ||
Links PaginationLinks `json:"_links"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.