forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheartbeat_store_request.go
More file actions
44 lines (37 loc) · 1.25 KB
/
Copy pathheartbeat_store_request.go
File metadata and controls
44 lines (37 loc) · 1.25 KB
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
package requests
import (
"time"
"github.com/NdoleStudio/httpsms/pkg/entities"
"github.com/NdoleStudio/httpsms/pkg/services"
)
// HeartbeatStore is the payload for fetching entities.Heartbeat of a phone number
type HeartbeatStore struct {
request
Owner string `json:"owner" swaggerignore:"true"`
Charging bool `json:"charging"`
PhoneNumbers []string `json:"phone_numbers"`
}
// Sanitize sets defaults to MessageOutstanding
func (input *HeartbeatStore) Sanitize() HeartbeatStore {
input.Owner = input.sanitizeAddress(input.Owner)
input.PhoneNumbers = input.sanitizeAddresses(input.PhoneNumbers)
if len(input.PhoneNumbers) == 0 {
input.PhoneNumbers = append(input.PhoneNumbers, input.Owner)
}
return *input
}
// ToStoreParams converts HeartbeatIndex to repositories.IndexParams
func (input *HeartbeatStore) ToStoreParams(user entities.AuthContext, source string, version string) []services.HeartbeatStoreParams {
var params []services.HeartbeatStoreParams
for _, phoneNumber := range input.PhoneNumbers {
params = append(params, services.HeartbeatStoreParams{
Owner: phoneNumber,
Charging: input.Charging,
Source: source,
Version: version,
UserID: user.ID,
Timestamp: time.Now(),
})
}
return params
}