Skip to content

Commit d938e29

Browse files
committed
refactor: 重构article的各类参数,使之更明确
1 parent 51eaf00 commit d938e29

22 files changed

+497
-252
lines changed

api/article/app/article.go

Lines changed: 90 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,107 @@ package app
22

33
import (
44
"github.com/gogf/gf/v2/frame/g"
5+
"github.com/gogf/gf/v2/os/gtime"
56
"github.com/oldme-git/oldme-api/internal/model"
67
)
78

8-
type ListReq struct {
9-
g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"app"`
10-
*model.ArticleQuerySafe
11-
}
9+
type (
10+
ListReq struct {
11+
g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"app"`
12+
model.Paging
13+
GrpId model.Id `v:"integer|between:1,4294967295" json:"grpId"`
14+
Search string `v:"length: 1,30" json:"search" dc:"查询文本,会检索标题、标签、简介"`
15+
}
1216

13-
type ListRes struct {
14-
List []model.ArticleListSafe `json:"list"`
15-
Total uint `json:"total"`
16-
}
17+
ListRes struct {
18+
List []List `json:"list"`
19+
Total uint `json:"total"`
20+
}
21+
)
1722

18-
type RankReq struct {
19-
g.Meta `path:"article/rank" method:"get" sm:"查询文章排行" tags:"app"`
20-
Basis int `v:"required|in:1,2" dc:"1-热门文章 2-最新文章"`
21-
}
23+
type (
24+
RankReq struct {
25+
g.Meta `path:"article/rank" method:"get" sm:"查询文章排行" tags:"app"`
26+
Basis int `v:"required|in:1,2" dc:"1-热门文章 2-最新文章"`
27+
}
2228

23-
type RankRes struct {
24-
List []model.ArticleListSafe `json:"list"`
25-
}
29+
RankRes struct {
30+
List []List `json:"list"`
31+
}
32+
)
2633

27-
type ShowReq struct {
28-
g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"app"`
29-
*model.IdInput
30-
}
34+
type (
35+
ShowReq struct {
36+
g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"app"`
37+
*model.IdInput
38+
}
3139

32-
type ShowRes struct {
33-
*model.ArticleSafe
34-
}
40+
ShowRes struct {
41+
*One
42+
}
43+
)
3544

36-
type AboutReq struct {
37-
g.Meta `path:"about" method:"get" sm:"查询关于我们" tags:"app"`
38-
}
45+
type (
46+
AboutReq struct {
47+
g.Meta `path:"about" method:"get" sm:"查询关于我们" tags:"app"`
48+
}
3949

40-
type AboutRes struct {
41-
*model.ArticleSafe
42-
}
50+
AboutRes struct {
51+
*One
52+
}
53+
)
4354

44-
type HistReq struct {
45-
g.Meta `path:"article/hist" method:"post" sm:"增加一个点击数" tags:"app"`
46-
*model.IdInput
47-
}
55+
type (
56+
HistReq struct {
57+
g.Meta `path:"article/hist" method:"post" sm:"增加一个点击数" tags:"app"`
58+
*model.IdInput
59+
}
4860

49-
type HistRes struct {
50-
}
61+
HistRes struct {
62+
}
63+
)
5164

52-
type ReplyReq struct {
53-
g.Meta `path:"article/reply/{id}" method:"get" sm:"查看该文章的回复" tags:"app"`
54-
model.IdInput
55-
}
65+
type (
66+
ReplyReq struct {
67+
g.Meta `path:"article/reply/{id}" method:"get" sm:"查看该文章的回复" tags:"app"`
68+
*model.IdInput
69+
}
5670

57-
type ReplyRes struct {
58-
List []model.ReplyFloorApp `json:"list"`
59-
Total uint `json:"total"`
60-
}
71+
ReplyRes struct {
72+
List []model.ReplyFloorApp `json:"list"`
73+
Total uint `json:"total"`
74+
}
75+
)
76+
77+
type (
78+
List struct {
79+
Id uint `json:"id" description:""`
80+
GrpId uint `json:"grpId" description:"分组id"`
81+
Title string `json:"title" description:"标题"`
82+
Author string `json:"author" description:"作者"`
83+
Thumb string `json:"thumb" description:"图片地址"`
84+
Tags string `json:"tags" description:"标签,依英文逗号隔开"`
85+
Description string `json:"description" description:"简介"`
86+
Hist uint `json:"hist" description:"点击数"`
87+
Post uint `json:"post" description:"评论数"`
88+
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
89+
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
90+
LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"`
91+
}
92+
93+
One struct {
94+
Id uint `json:"id" description:""`
95+
GrpId uint `json:"grpId" description:"分组id"`
96+
Title string `json:"title" description:"标题"`
97+
Author string `json:"author" description:"作者"`
98+
Thumb string `json:"thumb" description:"图片地址"`
99+
Tags string `json:"tags" description:"标签,依英文逗号隔开"`
100+
Description string `json:"description" description:"简介"`
101+
Content string `json:"content" description:"内容"`
102+
Hist uint `json:"hist" description:"点击数"`
103+
Post uint `json:"post" description:"评论数"`
104+
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
105+
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
106+
LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"`
107+
}
108+
)

api/article/v1/article.go

Lines changed: 132 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,136 @@ package v1
22

33
import (
44
"github.com/gogf/gf/v2/frame/g"
5+
"github.com/gogf/gf/v2/os/gtime"
56
"github.com/oldme-git/oldme-api/internal/model"
6-
"github.com/oldme-git/oldme-api/internal/model/entity"
7-
)
8-
9-
type CreReq struct {
10-
g.Meta `path:"article/create" method:"post" sm:"新增" tags:"文章"`
11-
*model.ArticleInput
12-
}
13-
14-
type CreRes struct {
15-
LastId model.Id `json:"lastId"`
16-
}
17-
18-
type UpdReq struct {
19-
g.Meta `path:"article/update/{id}" method:"post" sm:"修改" tags:"文章"`
20-
*model.IdInput
21-
*model.ArticleInput
22-
}
23-
24-
type UpdRes struct {
25-
}
26-
27-
type DelReq struct {
28-
g.Meta `path:"article/delete/{id}" method:"post" sm:"删除" tags:"文章"`
29-
*model.IdInput
30-
IsReal bool `dc:"是否彻底删除"`
31-
}
32-
33-
type DelRes struct {
34-
}
35-
36-
type ListReq struct {
37-
g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"文章"`
38-
*model.ArticleQuery
39-
}
40-
41-
type ListRes struct {
42-
List []model.ArticleList `json:"list"`
43-
Total uint `json:"total"`
44-
}
45-
46-
type ShowReq struct {
47-
g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"文章"`
48-
*model.IdInput
49-
}
50-
51-
type ShowRes struct {
52-
*entity.Article
53-
}
54-
55-
type ReCreReq struct {
56-
g.Meta `path:"article/recreate/{id}" method:"post" sm:"找回文章" tags:"文章"`
57-
*model.IdInput
58-
}
59-
60-
type ReCreRes struct {
61-
}
7+
)
8+
9+
type (
10+
CreReq struct {
11+
g.Meta `path:"article/create" method:"post" sm:"新增" tags:"文章"`
12+
GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"`
13+
Title string `json:"title" v:"required|length:2, 100"`
14+
Author string `json:"author" v:"length:2, 30"`
15+
Thumb string `json:"thumb" v:"length:2, 200"`
16+
Tags string `json:"tags" v:"length:2, 200"`
17+
Description string `json:"description" v:"length:2, 200"`
18+
Content string `json:"content" v:"length:2, 100000"`
19+
Order int `json:"order" v:"integer|between:-9999,9999"`
20+
Ontop uint `json:"ontop" v:"boolean"`
21+
Onshow uint `json:"onshow" v:"boolean"`
22+
Hist uint `json:"hist" v:"integer|between:0,999999"`
23+
Post uint `json:"post" v:"integer|between:0,999999"`
24+
}
25+
26+
CreRes struct {
27+
LastId model.Id `json:"lastId"`
28+
}
29+
)
30+
31+
type (
32+
UpdReq struct {
33+
g.Meta `path:"article/update/{id}" method:"post" sm:"修改" tags:"文章"`
34+
*model.IdInput
35+
GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"`
36+
Title string `json:"title" v:"required|length:2, 100"`
37+
Author string `json:"author" v:"length:2, 30"`
38+
Thumb string `json:"thumb" v:"length:2, 200"`
39+
Tags string `json:"tags" v:"length:2, 200"`
40+
Description string `json:"description" v:"length:2, 200"`
41+
Content string `json:"content" v:"length:2, 100000"`
42+
Order int `json:"order" v:"integer|between:-9999,9999"`
43+
Ontop uint `json:"ontop" v:"boolean"`
44+
Onshow uint `json:"onshow" v:"boolean"`
45+
Hist uint `json:"hist" v:"integer|between:0,999999"`
46+
Post uint `json:"post" v:"integer|between:0,999999"`
47+
}
48+
49+
UpdRes struct{}
50+
)
51+
52+
type (
53+
DelReq struct {
54+
g.Meta `path:"article/delete/{id}" method:"post" sm:"删除" tags:"文章"`
55+
*model.IdInput
56+
IsReal bool `dc:"是否彻底删除"`
57+
}
58+
59+
DelRes struct{}
60+
)
61+
62+
type (
63+
ListReq struct {
64+
g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"文章"`
65+
model.Paging
66+
GrpId model.Id `v:"integer|between:1,4294967295" json:"grpId"`
67+
Search string `v:"length: 1,30" json:"search" dc:"查询文本,会检索标题、标签、简介"`
68+
Onshow bool `json:"onshow" dc:"是否查询只发布的文章"`
69+
IsDel bool `json:"isDel" dc:"是否查询删除掉的文章"`
70+
}
71+
72+
ListRes struct {
73+
List []List `json:"list"`
74+
Total uint `json:"total"`
75+
}
76+
)
77+
78+
type (
79+
ShowReq struct {
80+
g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"文章"`
81+
*model.IdInput
82+
}
83+
84+
ShowRes struct {
85+
*One
86+
}
87+
)
88+
89+
type (
90+
ReCreReq struct {
91+
g.Meta `path:"article/recreate/{id}" method:"post" sm:"找回文章" tags:"文章"`
92+
*model.IdInput
93+
}
94+
95+
ReCreRes struct {
96+
}
97+
)
98+
99+
type (
100+
List struct {
101+
Id uint `json:"id" description:""`
102+
GrpId uint `json:"grpId" description:"分组id"`
103+
Title string `json:"title" description:"标题"`
104+
Author string `json:"author" description:"作者"`
105+
Thumb string `json:"thumb" description:"图片地址"`
106+
Tags string `json:"tags" description:"标签,依英文逗号隔开"`
107+
Description string `json:"description" description:"简介"`
108+
Order int `json:"order" description:"排序,越大越靠前"`
109+
Ontop uint `json:"ontop" description:"是否置顶"`
110+
Onshow uint `json:"onshow" description:"是否显示"`
111+
Hist uint `json:"hist" description:"点击数"`
112+
Post uint `json:"post" description:"评论数"`
113+
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
114+
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
115+
LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"`
116+
}
117+
118+
One struct {
119+
Id uint `json:"id" description:""`
120+
GrpId uint `json:"grpId" description:"分组id"`
121+
Title string `json:"title" description:"标题"`
122+
Author string `json:"author" description:"作者"`
123+
Thumb string `json:"thumb" description:"图片地址"`
124+
Tags string `json:"tags" description:"标签,依英文逗号隔开"`
125+
Description string `json:"description" description:"简介"`
126+
Content string `json:"content" description:"内容"`
127+
Order int `json:"order" description:"排序,越大越靠前"`
128+
Ontop uint `json:"ontop" description:"是否置顶"`
129+
Onshow uint `json:"onshow" description:"是否显示"`
130+
Hist uint `json:"hist" description:"点击数"`
131+
Post uint `json:"post" description:"评论数"`
132+
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
133+
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
134+
DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"`
135+
LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"`
136+
}
137+
)

api/article_grp/app/article_grp.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ package app
22

33
import (
44
"github.com/gogf/gf/v2/frame/g"
5-
"github.com/oldme-git/oldme-api/internal/model"
65
)
76

87
type ListReq struct {
98
g.Meta `path:"article/group/list" method:"get" sm:"查询列表" tags:"app"`
109
}
1110

1211
type ListRes struct {
13-
List []model.ArticleGrpListSafe `json:"list"`
12+
List []List `json:"list"`
13+
}
14+
15+
type List struct {
16+
Id uint `json:"id" description:""`
17+
Name string `json:"name" description:"名称"`
18+
Tags string `json:"tags" description:"标签,依英文逗号隔开"`
19+
Description string `json:"description" description:"简介"`
20+
ArticleCount uint `json:"article_count"`
1421
}

api/article_grp/v1/article_grp.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import (
77
)
88

99
type CreReq struct {
10-
g.Meta `path:"article/group/create" method:"post" sm:"新增" tags:"文章分类"`
11-
*model.ArticleGrpInput
10+
g.Meta `path:"article/group/create" method:"post" sm:"新增" tags:"文章分类"`
11+
Name string `v:"required|length:2, 30"`
12+
Tags string `v:"length:1, 200"`
13+
Description string `v:"length:2, 200"`
14+
Onshow bool `v:"required"`
15+
Order int `json:"order" v:"integer|between:-9999,9999"`
1216
}
1317

1418
type CreRes struct {
@@ -17,7 +21,11 @@ type CreRes struct {
1721
type UpdReq struct {
1822
g.Meta `path:"article/group/update/{id}" method:"post" sm:"修改" tags:"文章分类"`
1923
*model.IdInput
20-
*model.ArticleGrpInput
24+
Name string `v:"required|length:2, 30"`
25+
Tags string `v:"length:1, 200"`
26+
Description string `v:"length:2, 200"`
27+
Onshow bool `v:"required"`
28+
Order int `json:"order" v:"integer|between:-9999,9999"`
2129
}
2230

2331
type UpdRes struct {

0 commit comments

Comments
 (0)