/
models.go
68 lines (54 loc) · 1.28 KB
/
models.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
62
63
64
65
66
67
68
package forum
import (
"github.com/kapmahc/lotus/engines/auth"
"github.com/kapmahc/lotus/web"
)
const (
//TypeMarkdown markdown
TypeMarkdown = "markdown"
//TypeHTML html
TypeHTML = "html"
)
//Article article
type Article struct {
web.Model
Title string `json:"title"`
Summary string `json:"summary"`
Body string `json:"body"`
Type string `json:"type"`
Vote int `json:"vote"`
UserID uint `json:"user_id"`
User auth.User `json:"user"`
Tags []Tag `json:"tags" gorm:"many2many:forum_articles_tags;"`
Comments []Comment `json:"comments"`
}
//TableName table name
func (p *Article) TableName() string {
return "forum_articles"
}
//Tag tag
type Tag struct {
web.Model
Name string `json:"name"`
Vote int `json:"vote"`
Articles []Article `json:"articles" gorm:"many2many:forum_articles_tags;"`
}
//TableName table name
func (p *Tag) TableName() string {
return "forum_tags"
}
//Comment comment
type Comment struct {
web.Model
Body string `json:"body"`
Type string `json:"type"`
Vote int `json:"vote"`
UserID uint `json:"user_id"`
User auth.User `json:"user"`
ArticleID uint `json:"article_id"`
Article Article `json:"article"`
}
//TableName table name
func (p *Comment) TableName() string {
return "forum_comments"
}