forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_thread_index_request.go
More file actions
57 lines (46 loc) · 1.55 KB
/
message_thread_index_request.go
File metadata and controls
57 lines (46 loc) · 1.55 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
45
46
47
48
49
50
51
52
53
54
55
56
57
package requests
import (
"strings"
"github.com/NdoleStudio/httpsms/pkg/entities"
"github.com/NdoleStudio/httpsms/pkg/repositories"
"github.com/NdoleStudio/httpsms/pkg/services"
)
// MessageThreadIndex is the payload fetching entities.MessageThread sent between 2 numbers
type MessageThreadIndex struct {
request
IsArchived string `json:"is_archived" query:"is_archived" example:"false"`
Skip string `json:"skip" query:"skip"`
Query string `json:"query" query:"query"`
Limit string `json:"limit" query:"limit"`
Owner string `json:"owner" query:"owner"`
}
// Sanitize sets defaults to MessageOutstanding
func (input *MessageThreadIndex) Sanitize() MessageThreadIndex {
if strings.TrimSpace(input.Limit) == "" {
input.Limit = "20"
}
if strings.TrimSpace(input.IsArchived) == "" {
input.IsArchived = "false"
}
input.IsArchived = input.sanitizeBool(input.IsArchived)
input.Query = strings.TrimSpace(input.Query)
input.Owner = input.sanitizeAddress(input.Owner)
input.Skip = strings.TrimSpace(input.Skip)
if input.Skip == "" {
input.Skip = "0"
}
return *input
}
// ToGetParams converts MessageThreadIndex into services.MessageThreadGetParams
func (input *MessageThreadIndex) ToGetParams(userID entities.UserID) services.MessageThreadGetParams {
return services.MessageThreadGetParams{
IndexParams: repositories.IndexParams{
Skip: input.getInt(input.Skip),
Query: input.Query,
Limit: input.getInt(input.Limit),
},
UserID: userID,
IsArchived: input.getBool(input.IsArchived),
Owner: input.Owner,
}
}