Skip to content

Commit

Permalink
feat(payments): add payments accounts pool system (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Dec 4, 2023
1 parent 766bb04 commit 0b02d3e
Show file tree
Hide file tree
Showing 20 changed files with 2,561 additions and 13 deletions.
8 changes: 8 additions & 0 deletions components/payments/cmd/api/internal/api/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package backend
import (
"context"

"github.com/formancehq/payments/cmd/api/internal/api/service"
"github.com/formancehq/payments/cmd/api/internal/storage"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
Expand All @@ -21,6 +22,13 @@ type Service interface {
ListPayments(ctx context.Context, pagination storage.PaginatorQuery) ([]*models.Payment, storage.PaginationDetails, error)
GetPayment(ctx context.Context, id string) (*models.Payment, error)
UpdatePaymentMetadata(ctx context.Context, paymentID models.PaymentID, metadata map[string]string) error
CreatePool(ctx context.Context, req *service.CreatePoolRequest) (*models.Pool, error)
AddAccountToPool(ctx context.Context, poolID string, req *service.AddAccountToPoolRequest) error
RemoveAccountFromPool(ctx context.Context, poolID string, accountID string) error
ListPools(ctx context.Context, pagination storage.PaginatorQuery) ([]*models.Pool, storage.PaginationDetails, error)
GetPool(ctx context.Context, poolID string) (*models.Pool, error)
GetPoolBalance(ctx context.Context, poolID string, atTime string) (*service.GetPoolBalanceResponse, error)
DeletePool(ctx context.Context, poolID string) error
}

type Backend interface {
Expand Down
104 changes: 104 additions & 0 deletions components/payments/cmd/api/internal/api/backend/backend_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/payments/cmd/api/internal/api/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func updateMetadataHandler(b backend.Backend) http.HandlerFunc {

var metadata service.UpdateMetadataRequest
if r.ContentLength == 0 {
api.BadRequest(w, ErrMissingBody, errors.New("body is required"))
api.BadRequest(w, ErrMissingOrInvalidBody, errors.New("body is required"))
return
}

err = json.NewDecoder(r.Body).Decode(&metadata)
if err != nil {
api.BadRequest(w, ErrInvalidBody, err)
api.BadRequest(w, ErrMissingOrInvalidBody, err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions components/payments/cmd/api/internal/api/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func TestMetadata(t *testing.T) {
name: "missing body",
paymentID: paymentID.String(),
expectedStatusCode: http.StatusBadRequest,
expectedErrorCode: ErrMissingBody,
expectedErrorCode: ErrMissingOrInvalidBody,
},
{
name: "invalid body",
paymentID: paymentID.String(),
body: "invalid",
expectedStatusCode: http.StatusBadRequest,
expectedErrorCode: ErrInvalidBody,
expectedErrorCode: ErrMissingOrInvalidBody,
},
{
name: "invalid paymentID",
Expand Down
11 changes: 5 additions & 6 deletions components/payments/cmd/api/internal/api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ const (
otelTracesFlag = "otel-traces"
serviceName = "Payments"

ErrUniqueReference = "CONFLICT"
ErrNotFound = "NOT_FOUND"
ErrInvalidID = "INVALID_ID"
ErrMissingBody = "MISSING_BODY"
ErrInvalidBody = "INVALID_BODY"
ErrValidation = "VALIDATION"
ErrUniqueReference = "CONFLICT"
ErrNotFound = "NOT_FOUND"
ErrInvalidID = "INVALID_ID"
ErrMissingOrInvalidBody = "MISSING_OR_INVALID_BODY"
ErrValidation = "VALIDATION"
)

func HTTPModule(serviceInfo api.ServiceInfo, bind string) fx.Option {
Expand Down
Loading

1 comment on commit 0b02d3e

@vercel
Copy link

@vercel vercel bot commented on 0b02d3e Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.