-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrassilka.go
48 lines (43 loc) · 1.53 KB
/
rassilka.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
package rassilki
import (
"errors"
"github.com/lib/pq"
"time"
)
type Rassilka struct {
Id int `json:"-" db:"id"`
StartTime time.Time `json:"start-time" db:"start_time" binding:"required"`
Message string `json:"message" db:"message" binding:"required"`
Filter pq.StringArray `json:"filter" db:"filter"`
EndTime time.Time `json:"end-time" db:"end_time" binding:"required"`
Supplemented bool `json:"-" db:"supplemented"`
Recreated bool `json:"-" db:"recreated"`
}
type UpdateRassilka struct {
StartTime *time.Time `json:"start-time" `
Message *string `json:"message" `
Filter *[]string `json:"filter"`
EndTime *time.Time `json:"end-time" `
Supplemented *bool `json:"supplemented"`
Recreated *bool `json:"recreated"`
}
func (i UpdateRassilka) Validate() error {
if i.StartTime == nil && i.Message == nil && i.EndTime == nil {
return errors.New("updating structure has no values")
}
if i.StartTime != nil && i.EndTime != nil {
if (*i.StartTime).After(*i.EndTime) {
return errors.New("StartTime is after EndTime")
}
}
if i.EndTime != nil && (*i.EndTime).Before(time.Now()) {
return errors.New("EndTime is in the past")
}
return nil
}
type RassilkaReview struct {
Id int `json:"ras_id" db:"ras_id"`
Total int `json:"total" db:"-"`
Sent int `json:"sent" db:"-"`
NotSent int `json:"not_sent" db:"-"`
}