Skip to content

Commit

Permalink
fix: connectors enabled flag (#75)
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com>

Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com>
  • Loading branch information
darkmatterpool committed Dec 30, 2022
1 parent 405b67d commit 2097a6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
18 changes: 13 additions & 5 deletions internal/app/api/readconnectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
13 changes: 0 additions & 13 deletions internal/app/payments/connector.go

This file was deleted.

0 comments on commit 2097a6f

Please sign in to comment.