mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package messages
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/formancehq/stack/libs/go-libs/publish"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/formancehq/payments/pkg/events"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type poolMessagePayload struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
AccountIDs []string `json:"accountIDs"`
|
|
}
|
|
|
|
func (m *Messages) NewEventSavedPool(pool *models.Pool) publish.EventMessage {
|
|
payload := poolMessagePayload{
|
|
ID: pool.ID.String(),
|
|
Name: pool.Name,
|
|
CreatedAt: pool.CreatedAt,
|
|
}
|
|
|
|
payload.AccountIDs = make([]string, len(pool.PoolAccounts))
|
|
for i, a := range pool.PoolAccounts {
|
|
payload.AccountIDs[i] = a.AccountID.String()
|
|
}
|
|
|
|
return publish.EventMessage{
|
|
Date: time.Now().UTC(),
|
|
App: events.EventApp,
|
|
Version: events.EventVersion,
|
|
Type: events.EventTypeSavedPool,
|
|
Payload: payload,
|
|
}
|
|
}
|
|
|
|
type deletePoolMessagePayload struct {
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (m *Messages) NewEventDeletePool(id uuid.UUID) publish.EventMessage {
|
|
return publish.EventMessage{
|
|
Date: time.Now().UTC(),
|
|
App: events.EventApp,
|
|
Version: events.EventVersion,
|
|
Type: events.EventTypeDeletePool,
|
|
Payload: deletePoolMessagePayload{
|
|
CreatedAt: time.Now().UTC(),
|
|
ID: id.String(),
|
|
},
|
|
}
|
|
}
|