-
Notifications
You must be signed in to change notification settings - Fork 12
/
event_reminder_notification.go
39 lines (33 loc) · 1.48 KB
/
event_reminder_notification.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
package reminder
import (
"time"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/validator"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/eventstore"
"github.com/pkg/errors"
)
type ReminderNotificationEvent struct {
Tenant string `json:"tenant" validate:"required"`
CreatedAt time.Time `json:"createdAt"`
ReminderId string `json:"reminderId" validate:"required"`
OrganizationId string `json:"organizationId" validate:"required"`
UserId string `json:"userId"` // who set the reminder
Content string `json:"content"`
}
func NewReminderNotificationEvent(aggregate eventstore.Aggregate, userId, organizationId, content string, createdAt time.Time) (eventstore.Event, error) {
eventData := ReminderNotificationEvent{
Tenant: aggregate.GetTenant(),
CreatedAt: createdAt,
ReminderId: GetReminderObjectID(aggregate.GetID(), aggregate.GetTenant()),
OrganizationId: organizationId,
UserId: userId,
Content: content,
}
if err := validator.GetValidator().Struct(eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "failed to validate ReminderNotificationEvent")
}
event := eventstore.NewBaseEvent(aggregate, ReminderNotificationV1)
if err := event.SetJsonData(&eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "error setting json data for ReminderNotificationEvent")
}
return event, nil
}