-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87dbab6
commit 96f9bec
Showing
104 changed files
with
3,434 additions
and
595 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...pod-latest/results/migrations-stack.formance.com-v1beta3/payments-v0.9.0-pre-upgrade.yaml
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,18 @@ | ||
apiVersion: stack.formance.com/v1beta3 | ||
kind: Migration | ||
metadata: | ||
annotations: | ||
reloader.stakater.com/auto: "true" | ||
generation: 1 | ||
labels: | ||
stack: "true" | ||
name: payments-v0.9.0-pre-upgrade | ||
namespace: monopod-latest | ||
spec: | ||
configuration: monopod-latest | ||
module: payments | ||
postUpgrade: false | ||
targetedVersion: v0.9.0 | ||
version: monopod-latest | ||
status: | ||
terminated: true |
18 changes: 18 additions & 0 deletions
18
...d-ledgerv1/results/migrations-stack.formance.com-v1beta3/payments-v0.9.0-pre-upgrade.yaml
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,18 @@ | ||
apiVersion: stack.formance.com/v1beta3 | ||
kind: Migration | ||
metadata: | ||
annotations: | ||
reloader.stakater.com/auto: "true" | ||
generation: 1 | ||
labels: | ||
stack: "true" | ||
name: payments-v0.9.0-pre-upgrade | ||
namespace: monopod-ledgerv1 | ||
spec: | ||
configuration: monopod-ledgerv1 | ||
module: payments | ||
postUpgrade: false | ||
targetedVersion: v0.9.0 | ||
version: monopod-ledgerv1 | ||
status: | ||
terminated: true |
18 changes: 18 additions & 0 deletions
18
...ore-v0.7.0/results/migrations-stack.formance.com-v1beta3/payments-v0.9.0-pre-upgrade.yaml
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,18 @@ | ||
apiVersion: stack.formance.com/v1beta3 | ||
kind: Migration | ||
metadata: | ||
annotations: | ||
reloader.stakater.com/auto: "true" | ||
generation: 1 | ||
labels: | ||
stack: "true" | ||
name: payments-v0.9.0-pre-upgrade | ||
namespace: monopod-search-before-v0-7-0 | ||
spec: | ||
configuration: monopod-search-before-v0-7-0 | ||
module: payments | ||
postUpgrade: false | ||
targetedVersion: v0.9.0 | ||
version: monopod-search-before-v0-7-0 | ||
status: | ||
terminated: true |
18 changes: 18 additions & 0 deletions
18
...pod-latest/results/migrations-stack.formance.com-v1beta3/payments-v0.9.0-pre-upgrade.yaml
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,18 @@ | ||
apiVersion: stack.formance.com/v1beta3 | ||
kind: Migration | ||
metadata: | ||
annotations: | ||
reloader.stakater.com/auto: "true" | ||
generation: 1 | ||
labels: | ||
stack: "true" | ||
name: payments-v0.9.0-pre-upgrade | ||
namespace: multipod-latest | ||
spec: | ||
configuration: multipod-latest | ||
module: payments | ||
postUpgrade: false | ||
targetedVersion: v0.9.0 | ||
version: multipod-latest | ||
status: | ||
terminated: true |
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,168 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/formancehq/payments/internal/app/models" | ||
"github.com/formancehq/payments/internal/app/storage" | ||
"github.com/formancehq/stack/libs/go-libs/api" | ||
"github.com/gorilla/mux" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type balancesRepository interface { | ||
ListBalances(ctx context.Context, query storage.BalanceQuery) ([]*models.Balance, storage.PaginationDetails, error) | ||
} | ||
|
||
type balancesResponse struct { | ||
AccountID string `json:"accountId"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
LastUpdatedAt time.Time `json:"lastUpdatedAt"` | ||
Currency string `json:"currency"` | ||
Balance int64 `json:"balance"` | ||
} | ||
|
||
func listBalancesForAccount(repo balancesRepository) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
var sorter storage.Sorter | ||
|
||
if sortParams := r.URL.Query()["sort"]; sortParams != nil { | ||
for _, s := range sortParams { | ||
parts := strings.SplitN(s, ":", 2) | ||
|
||
var order storage.SortOrder | ||
|
||
if len(parts) > 1 { | ||
//nolint:goconst // allow duplicate string | ||
switch parts[1] { | ||
case "asc", "ASC": | ||
order = storage.SortOrderAsc | ||
case "dsc", "desc", "DSC", "DESC": | ||
order = storage.SortOrderDesc | ||
default: | ||
handleValidationError(w, r, errors.New("sort order not well specified, got "+parts[1])) | ||
|
||
return | ||
} | ||
} | ||
|
||
column := parts[0] | ||
|
||
sorter.Add(column, order) | ||
} | ||
} | ||
|
||
pageSize, err := pageSizeQueryParam(r) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
|
||
pagination, err := storage.Paginate(pageSize, r.URL.Query().Get("cursor"), sorter) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
|
||
accountID, err := models.AccountIDFromString(mux.Vars(r)["accountID"]) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
|
||
balanceQuery := storage.NewBalanceQuery(pagination). | ||
WithAccountID(accountID). | ||
WithCurrency(r.URL.Query().Get("currency")) | ||
|
||
var startTimeParsed, endTimeParsed time.Time | ||
from, to := r.URL.Query().Get("from"), r.URL.Query().Get("to") | ||
if from != "" { | ||
startTimeParsed, err = time.Parse(time.RFC3339Nano, from) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
} | ||
if to != "" { | ||
endTimeParsed, err = time.Parse(time.RFC3339Nano, to) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
} | ||
if r.URL.Query().Get("limit") != "" { | ||
limit, err := strconv.ParseInt(r.URL.Query().Get("limit"), 10, 64) | ||
if err != nil { | ||
handleValidationError(w, r, err) | ||
|
||
return | ||
} | ||
|
||
if limit > 0 { | ||
balanceQuery = balanceQuery.WithLimit(int(limit)) | ||
} | ||
} | ||
|
||
switch { | ||
case startTimeParsed.IsZero() && endTimeParsed.IsZero(): | ||
balanceQuery = balanceQuery. | ||
WithTo(time.Now()) | ||
case !startTimeParsed.IsZero() && endTimeParsed.IsZero(): | ||
balanceQuery = balanceQuery. | ||
WithFrom(startTimeParsed). | ||
WithTo(time.Now()) | ||
case startTimeParsed.IsZero() && !endTimeParsed.IsZero(): | ||
balanceQuery = balanceQuery. | ||
WithTo(endTimeParsed) | ||
default: | ||
balanceQuery = balanceQuery. | ||
WithFrom(startTimeParsed). | ||
WithTo(endTimeParsed) | ||
} | ||
|
||
ret, paginationDetails, err := repo.ListBalances(r.Context(), balanceQuery) | ||
if err != nil { | ||
handleServerError(w, r, err) | ||
|
||
return | ||
} | ||
|
||
data := make([]*balancesResponse, len(ret)) | ||
for i := range ret { | ||
data[i] = &balancesResponse{ | ||
AccountID: ret[i].AccountID.String(), | ||
CreatedAt: ret[i].CreatedAt, | ||
Currency: ret[i].Currency, | ||
Balance: ret[i].Balance, | ||
LastUpdatedAt: ret[i].LastUpdatedAt, | ||
} | ||
} | ||
|
||
err = json.NewEncoder(w).Encode(api.BaseResponse[*balancesResponse]{ | ||
Cursor: &api.Cursor[*balancesResponse]{ | ||
PageSize: paginationDetails.PageSize, | ||
HasMore: paginationDetails.HasMore, | ||
Previous: paginationDetails.PreviousPage, | ||
Next: paginationDetails.NextPage, | ||
Data: data, | ||
}, | ||
}) | ||
if err != nil { | ||
handleServerError(w, r, err) | ||
|
||
return | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
96f9bec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./
docs-git-main-formance.vercel.app
docs-formance.vercel.app
docs.formance.com
developers.numary.com
docs.numary.com
developers.formance.com