-
Notifications
You must be signed in to change notification settings - Fork 11
/
schedule.go
59 lines (47 loc) · 1.27 KB
/
schedule.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
57
58
59
package publish2
import (
"time"
"github.com/jinzhu/gorm"
"github.com/qor/validations"
)
type Schedule struct {
ScheduledStartAt *time.Time `gorm:"index"`
ScheduledEndAt *time.Time `gorm:"index"`
ScheduledEventID *uint
}
func (schedule *Schedule) GetScheduledStartAt() *time.Time {
return schedule.ScheduledStartAt
}
func (schedule *Schedule) SetScheduledStartAt(t *time.Time) {
schedule.ScheduledStartAt = t
}
func (schedule *Schedule) GetScheduledEndAt() *time.Time {
return schedule.ScheduledEndAt
}
func (schedule *Schedule) SetScheduledEndAt(t *time.Time) {
schedule.ScheduledEndAt = t
}
func (schedule *Schedule) GetScheduledEventID() *uint {
return schedule.ScheduledEventID
}
type ScheduledInterface interface {
GetScheduledStartAt() *time.Time
SetScheduledStartAt(*time.Time)
GetScheduledEndAt() *time.Time
SetScheduledEndAt(*time.Time)
GetScheduledEventID() *uint
}
type ScheduledEvent struct {
gorm.Model
Name string
ScheduledStartAt *time.Time
ScheduledEndAt *time.Time
}
func (scheduledEvent ScheduledEvent) ToParam() string {
return "scheduled_events"
}
func (scheduledEvent ScheduledEvent) BeforeSave(tx *gorm.DB) {
if scheduledEvent.Name == "" {
tx.AddError(validations.NewError(scheduledEvent, "Name", "Name can not be empty"))
}
}