-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications_dto.go
56 lines (48 loc) · 1.85 KB
/
notifications_dto.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
55
56
package notifications_dto
import (
"github.com/golanshy/plime_core-go/utils/rest_errors"
"strings"
)
type MessageContent struct {
MessageTitle string `json:"message_title"`
MessageSubTitle string `json:"message_sub_title"`
MessagePart1 string `json:"message_part_1"`
MessagePart2 string `json:"message_part_2"`
MessagePart3 string `json:"message_part_3"`
BodyImage string `json:"body_image"`
BodyImageUrl string `json:"body_image_url"`
ActionButtonText string `json:"action_button_text"`
ActionButtonURL string `json:"action_button_url"`
}
type NotificationRequest struct {
Channel string `json:"channel"`
UserIds []string `json:"user_ids"`
Destinations []string `json:"destinations,omitempty"`
Subject string `json:"subject,omitempty"`
HtmlMessage string `json:"html_message,omitempty"`
HtmlMessageContent MessageContent `json:"html_message_content"`
Message string `json:"message,omitempty"`
Payload string `json:"payload,omitempty"`
DateCreated string `json:"date_created"`
}
const (
ChannelEmail string = "email"
ChannelText string = "text"
ChannelWhatsApp string = "whatsapp"
ChannelPush string = "push"
)
func (r *NotificationRequest) Validate() *rest_errors.RestErr {
if len(r.UserIds) == 0 && len(r.Destinations) == 0 {
return rest_errors.NewBadRequestError("missing user ids or destinations")
}
if strings.TrimSpace(r.Channel) == "" {
return rest_errors.NewBadRequestError("missing channel")
}
if strings.TrimSpace(r.Channel) == ChannelEmail &&
strings.TrimSpace(r.Channel) == ChannelText &&
strings.TrimSpace(r.Channel) == ChannelWhatsApp &&
strings.TrimSpace(r.Channel) == ChannelPush {
return rest_errors.NewBadRequestError("invalid channel")
}
return nil
}