From 2097a6f1cb2a30400ae7ab4e04ce85cf5ed5af5f Mon Sep 17 00:00:00 2001 From: darkmatterpool <113581282+darkmatterpool@users.noreply.github.com> Date: Fri, 30 Dec 2022 13:00:38 +0200 Subject: [PATCH] fix: connectors enabled flag (#75) Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com> Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com> --- internal/app/api/readconnectors.go | 18 +++++++++++++----- internal/app/payments/connector.go | 13 ------------- 2 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 internal/app/payments/connector.go diff --git a/internal/app/api/readconnectors.go b/internal/app/api/readconnectors.go index e2e1f330..a9bf2b4d 100644 --- a/internal/app/api/readconnectors.go +++ b/internal/app/api/readconnectors.go @@ -8,13 +8,20 @@ import ( "github.com/formancehq/payments/internal/app/models" "github.com/formancehq/go-libs/sharedapi" - "github.com/formancehq/payments/internal/app/payments" ) type readConnectorsRepository interface { ListConnectors(ctx context.Context) ([]*models.Connector, error) } +type readConnectorsResponseElement struct { + Provider models.ConnectorProvider `json:"provider" bson:"provider"` + Enabled bool `json:"enabled" bson:"enabled"` + + // TODO: remove disabled field when frontend switches to using enabled + Disabled bool `json:"disabled" bson:"disabled"` +} + func readConnectorsHandler(repo readConnectorsRepository) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { res, err := repo.ListConnectors(r.Context()) @@ -24,17 +31,18 @@ func readConnectorsHandler(repo readConnectorsRepository) http.HandlerFunc { return } - data := make([]*payments.ConnectorBaseInfo, len(res)) + data := make([]readConnectorsResponseElement, len(res)) for i := range res { - data[i] = &payments.ConnectorBaseInfo{ + data[i] = readConnectorsResponseElement{ Provider: res[i].Provider, - Disabled: res[i].Enabled, + Enabled: res[i].Enabled, + Disabled: !res[i].Enabled, } } err = json.NewEncoder(w).Encode( - sharedapi.BaseResponse[[]*payments.ConnectorBaseInfo]{ + sharedapi.BaseResponse[[]readConnectorsResponseElement]{ Data: &data, }) if err != nil { diff --git a/internal/app/payments/connector.go b/internal/app/payments/connector.go deleted file mode 100644 index 5f16302e..00000000 --- a/internal/app/payments/connector.go +++ /dev/null @@ -1,13 +0,0 @@ -package payments - -import "github.com/formancehq/payments/internal/app/models" - -type ConnectorBaseInfo struct { - Provider models.ConnectorProvider `json:"provider" bson:"provider"` - Disabled bool `json:"disabled" bson:"disabled"` -} - -type Connector[T ConnectorConfigObject] struct { - ConnectorBaseInfo - Config T `json:"config" bson:"config"` -}