-
Notifications
You must be signed in to change notification settings - Fork 832
/
notification.go
61 lines (50 loc) · 1.55 KB
/
notification.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
60
61
package models
import (
"time"
)
const (
TableNameNotification = "notification"
)
type notificationModel struct{}
type NotificationType string
const (
NoticeNotification NotificationType = "公告"
WarningNotification NotificationType = "警告"
)
type NotificationLevel int
const (
LowNotification NotificationLevel = iota
MiddleNotification
HighNotification
)
type Notification struct {
Id int64 `orm:"auto" json:"id,omitempty"`
Type NotificationType `orm:"index;size(128)" json:"type,omitempty"`
Title string `orm:"size(2000)" json:"title,omitempty"`
Message string `orm:"type(text)" json:"message,omitempty"`
FromUser *User `orm:"index;rel(fk)" json:"from,omitempty"`
Level NotificationLevel `orm:"default(0)" json:"level,omitempty"`
IsPublished bool `orm:"default(false)" json:"is_published"`
CreateTime *time.Time `orm:"auto_now_add;type(datetime)" json:"createTime,omitempty"`
UpdateTime *time.Time `orm:"auto_now;type(datetime)" json:"updateTime,omitempty"`
}
func (*Notification) TableName() string {
return TableNameNotification
}
func (*notificationModel) Add(n *Notification) (id int64, err error) {
// 创建通知
id, err = Ormer().Insert(n)
if err != nil {
return
}
return
}
func (*notificationModel) UpdateById(n *Notification) (err error) {
v := Notification{Id: n.Id}
// ascertain id exists in the database
if err = Ormer().Read(&v); err == nil {
_, err := Ormer().Update(n, "IsPublished")
return err
}
return err
}