-
Notifications
You must be signed in to change notification settings - Fork 2
/
event.go
54 lines (44 loc) · 1.16 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package userbus
import (
"fmt"
"github.com/ardanlabs/encore/business/sdk/delegate"
"github.com/go-json-experiment/json"
"github.com/google/uuid"
)
// Name represents the name of this domain.
const Name = "user"
// Set of delegate actions.
const (
ActionUpdated = "updated"
)
// ActionUpdatedParms represents the parameters for the updated action.
type ActionUpdatedParms struct {
UserID uuid.UUID
UpdateUser
}
// String returns a string representation of the action parameters.
func (au *ActionUpdatedParms) String() string {
return fmt.Sprintf("&EventParamsUpdated{UserID:%v, Enabled:%v}", au.UserID, au.Enabled)
}
// Marshal returns the event parameters encoded as JSON.
func (au *ActionUpdatedParms) Marshal() ([]byte, error) {
return json.Marshal(au)
}
// ActionUpdatedData constructs the data for the updated action.
func ActionUpdatedData(uu UpdateUser, userID uuid.UUID) delegate.Data {
params := ActionUpdatedParms{
UserID: userID,
UpdateUser: UpdateUser{
Enabled: uu.Enabled,
},
}
rawParams, err := params.Marshal()
if err != nil {
panic(err)
}
return delegate.Data{
Domain: Name,
Action: ActionUpdated,
RawParams: rawParams,
}
}