-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send kafka message when connector is reset (#82)
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
1 parent
b80d1ce
commit 0c89897
Showing
10 changed files
with
170 additions
and
111 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
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 was deleted.
Oops, something went wrong.
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
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,37 @@ | ||
package messages | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/formancehq/payments/internal/app/models" | ||
) | ||
|
||
type accountMessagePayload struct { | ||
ID string `json:"id"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
Reference string `json:"reference"` | ||
Provider string `json:"provider"` | ||
Type models.AccountType `json:"type"` | ||
} | ||
|
||
func NewEventSavedAccounts(accounts []models.Account) EventMessage { | ||
payload := make([]accountMessagePayload, len(accounts)) | ||
|
||
for accountIdx, account := range accounts { | ||
payload[accountIdx] = accountMessagePayload{ | ||
ID: account.ID.String(), | ||
CreatedAt: account.CreatedAt, | ||
Reference: account.Reference, | ||
Provider: account.Provider, | ||
Type: account.Type, | ||
} | ||
} | ||
|
||
return EventMessage{ | ||
Date: time.Now().UTC(), | ||
App: EventApp, | ||
Version: EventVersion, | ||
Type: EventTypeSavedAccounts, | ||
Payload: payload, | ||
} | ||
} |
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,25 @@ | ||
package messages | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/formancehq/payments/internal/app/models" | ||
) | ||
|
||
type connectorMessagePayload struct { | ||
CreatedAt time.Time `json:"createdAt"` | ||
Connector models.ConnectorProvider `json:"connector"` | ||
} | ||
|
||
func NewEventResetConnector(connector models.ConnectorProvider) EventMessage { | ||
return EventMessage{ | ||
Date: time.Now().UTC(), | ||
App: EventApp, | ||
Version: EventVersion, | ||
Type: EventTypeConnectorReset, | ||
Payload: connectorMessagePayload{ | ||
CreatedAt: time.Now().UTC(), | ||
Connector: connector, | ||
}, | ||
} | ||
} |
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,25 @@ | ||
package messages | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
const ( | ||
TopicPayments = "payments" | ||
TopicConnectors = "connectors" | ||
|
||
EventVersion = "v1" | ||
EventApp = "payments" | ||
|
||
EventTypeSavedPayments = "SAVED_PAYMENT" | ||
EventTypeSavedAccounts = "SAVED_ACCOUNT" | ||
EventTypeConnectorReset = "CONNECTOR_RESET" | ||
) | ||
|
||
type EventMessage struct { | ||
Date time.Time `json:"date"` | ||
App string `json:"app"` | ||
Version string `json:"version"` | ||
Type string `json:"type"` | ||
Payload any `json:"payload"` | ||
} |
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,45 @@ | ||
package messages | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/formancehq/payments/internal/app/models" | ||
) | ||
|
||
type paymentMessagePayload struct { | ||
ID string `json:"id"` | ||
Reference string `json:"reference"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
Provider string `json:"provider"` | ||
Type models.PaymentType `json:"type"` | ||
Status models.PaymentStatus `json:"status"` | ||
Scheme models.PaymentScheme `json:"scheme"` | ||
Asset models.PaymentAsset `json:"asset"` | ||
|
||
// TODO: Remove 'initialAmount' once frontend has switched to 'amount | ||
InitialAmount int64 `json:"initialAmount"` | ||
Amount int64 `json:"amount"` | ||
} | ||
|
||
func NewEventSavedPayments(payment *models.Payment, provider models.ConnectorProvider) EventMessage { | ||
payload := paymentMessagePayload{ | ||
ID: payment.ID.String(), | ||
Reference: payment.Reference, | ||
Type: payment.Type, | ||
Status: payment.Status, | ||
InitialAmount: payment.Amount, | ||
Scheme: payment.Scheme, | ||
Asset: payment.Asset, | ||
CreatedAt: payment.CreatedAt, | ||
Amount: payment.Amount, | ||
Provider: provider.String(), | ||
} | ||
|
||
return EventMessage{ | ||
Date: time.Now().UTC(), | ||
App: EventApp, | ||
Version: EventVersion, | ||
Type: EventTypeSavedPayments, | ||
Payload: payload, | ||
} | ||
} |