File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package smsgateway
22
33import (
4+ "fmt"
45 "net/url"
56 "strconv"
67 "time"
@@ -86,13 +87,22 @@ func (o ListInboxOptions) ToURLValues() url.Values {
8687
8788// ListMessagesOptions holds optional filters for listing messages.
8889type ListMessagesOptions struct {
89- From * time.Time
90- To * time.Time
91- State * string
92- DeviceID * string
93- Limit * int
94- Offset * int
95- IncludeContent * bool
90+ From * time.Time `query:"from" validate:"omitempty"`
91+ To * time.Time `query:"to" validate:"omitempty"`
92+ State * string `query:"state" validate:"omitempty,oneof=Pending Cancelling Cancelled Processed Sent Delivered Failed"`
93+ DeviceID * string `query:"deviceId" validate:"omitempty,len=21"`
94+ Limit * int `query:"limit" validate:"omitempty,min=1,max=100"`
95+ Offset * int `query:"offset" validate:"omitempty,min=0"`
96+ IncludeContent * bool `query:"includeContent"`
97+ }
98+
99+ // Validate checks if the ListMessagesOptions are valid.
100+ func (o ListMessagesOptions ) Validate () error {
101+ if o .From != nil && o .To != nil && o .From .After (* o .To ) {
102+ return fmt .Errorf ("%w: `from` date must be before `to` date" , ErrValidationFailed )
103+ }
104+
105+ return nil
96106}
97107
98108// ToURLValues returns the ListMessagesOptions as URL query parameters.
You can’t perform that action at this time.
0 commit comments