Skip to content

Commit 0f1b484

Browse files
committed
Create notification model/table
1 parent cbcb436 commit 0f1b484

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

models/models.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,40 @@ var (
6868

6969
func init() {
7070
tables = append(tables,
71-
new(User), new(PublicKey), new(AccessToken),
72-
new(Repository), new(DeployKey), new(Collaboration), new(Access), new(Upload),
73-
new(Watch), new(Star), new(Follow), new(Action),
74-
new(Issue), new(PullRequest), new(Comment), new(Attachment), new(IssueUser),
75-
new(Label), new(IssueLabel), new(Milestone),
76-
new(Mirror), new(Release), new(LoginSource), new(Webhook),
77-
new(UpdateTask), new(HookTask),
78-
new(Team), new(OrgUser), new(TeamUser), new(TeamRepo),
79-
new(Notice), new(EmailAddress))
71+
new(User),
72+
new(PublicKey),
73+
new(AccessToken),
74+
new(Repository),
75+
new(DeployKey),
76+
new(Collaboration),
77+
new(Access),
78+
new(Upload),
79+
new(Watch),
80+
new(Star),
81+
new(Follow),
82+
new(Action),
83+
new(Issue),
84+
new(PullRequest),
85+
new(Comment),
86+
new(Attachment),
87+
new(IssueUser),
88+
new(Label),
89+
new(IssueLabel),
90+
new(Milestone),
91+
new(Mirror),
92+
new(Release),
93+
new(LoginSource),
94+
new(Webhook),
95+
new(UpdateTask),
96+
new(HookTask),
97+
new(Team),
98+
new(OrgUser),
99+
new(TeamUser),
100+
new(TeamRepo),
101+
new(Notice),
102+
new(EmailAddress),
103+
new(Notification),
104+
)
80105

81106
gonicNames := []string{"SSL", "UID"}
82107
for _, name := range gonicNames {

models/notification.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package models
2+
3+
import (
4+
"time"
5+
)
6+
7+
const (
8+
NotificationStatusUnread = "U"
9+
NotificationStatusRead = "R"
10+
11+
NotificationSourceIssue = "I"
12+
NotificationSourcePullRequest = "P"
13+
NotificationSourceCommit = "C"
14+
)
15+
16+
type Notification struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
UserID int64 `xorm:"INDEX NOT NULL"`
19+
RepoID int64 `xorm:"INDEX NOT NULL"`
20+
21+
Status string `xorm:"VARCHAR(1) INDEX NOT NULL"`
22+
Source string `xorm:"VARCHAR(1) INDEX NOT NULL"`
23+
24+
IssueID int64 `xorm:"INDEX NOT NULL"`
25+
PullID int64 `xorm:"INDEX"`
26+
CommitID string `xorm:"INDEX"`
27+
28+
Issue *Issue `xorm:"-"`
29+
PullRequest *PullRequest `xorm:"-"`
30+
31+
Created time.Time `xorm:"-"`
32+
CreatedUnix int64 `xorm:"INDEX NOT NULL"`
33+
Updated time.Time `xorm:"-"`
34+
UpdatedUnix int64 `xorm:"INDEX NOT NULL"`
35+
}
36+
37+
func (n *Notification) BeforeInsert() {
38+
var (
39+
now = time.Now()
40+
nowUnix = now.Unix()
41+
)
42+
n.Created = now
43+
n.CreatedUnix = nowUnix
44+
n.Updated = now
45+
n.UpdatedUnix = nowUnix
46+
}
47+
func (n *Notification) BeforeUpdate() {
48+
var (
49+
now = time.Now()
50+
nowUnix = now.Unix()
51+
)
52+
n.Updated = now
53+
n.UpdatedUnix = nowUnix
54+
}

0 commit comments

Comments
 (0)