@@ -85,87 +85,314 @@ $ go run main.go
8585
8686![ image-20200419175221473] (/Users/MING/Library/Application Support/typora-user-images/image-20200419175221473.png)
8787
88- ## 3. 前端环境搭建
89-
9088
9189
9290## 4. 表的设计
9391
94- ### 文章(posts)
92+ ### 用户(users)
93+
94+ | 字段 | 类型 | 说明 | 角色 |
95+ | --------------- | ------------ | ------------ | ---- |
96+ | id | int(10) | | 主键 |
97+ | name | varchar(100) | 用户名 | |
98+ | passwd | varchar(100) | 密码 | |
99+ | email | varchar(100) | 邮箱 | |
100+ | profile_picture | varchar(100) | 头像路径 | |
101+ | last_login | timestamp | 最后登陆时间 | |
102+ | create_time | timestamp | 创建时间 | |
103+ | update_times | timestamp | 更新时间 | |
104+ | delete_times | timestamp | 删除时间 | |
105+
106+ ``` mysql
107+ CREATE TABLE `users ` (
108+ ` id` int (10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
109+ ` name` varchar (100 ) NOT NULL COMMENT ' 用户名' ,
110+ ` passwd` VARCHAR (100 ) NOT NULL COMMENT ' 密码' ,
111+ ` email` VARCHAR (100 ) DEFAULT ' ' COMMENT ' 邮箱' ,
112+ ` profile_picture` VARCHAR (10 ) COMMENT ' 头像路径' ,
113+ ` last_login` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 最后登陆时间' ,
114+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
115+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 更新时间' ,
116+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
117+
118+ PRIMARY KEY (` id` )
119+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 用户管理' ;
120+ ```
121+
95122
96- | 字段 | 类型 | 说明 | 角色 |
97- | ----------- | ---- | -------- | ----------- |
98- | id | int | | 主键 |
99- | title | char | 标题 | |
100- | tag_id | int | 标签 | 外键 |
101- | author | int | 作者 | 外键 |
102- | content | text | 正文 | |
103- | update_timestamp | timestamp | 更新时间 | |
104- | create_timestamp | timestamp | 发布时间 | |
105- | category_id | int | 类别 | 外键 |
106- | page_view | int | 浏览量 | |
107- | like_count | int | 点赞数 | |
108123
109- ### 标签(Tags )
124+ ### 标签(tags )
110125
111- | 字段 | 类型 | 说明 | 角色 |
126+ | 字段 | 类型 | 说明 | 属性 |
112127| ----- | ---- | -------- | ----- |
113- | id | int | | 主键 |
114- | name | char | 标签名 | |
115- | count | int | 文章数量 | |
116- | create_timestamp | timestamp | 创建时间 | |
117- | update_timestamp | timestamp | 更新时间 | |
128+ | id | int(10) | | 主键 |
129+ | name | varchar(100) | 标签名 | |
130+ | count | int(10) | 文章数量 | |
131+ | create_time | timestamp | 创建时间 | |
132+ | update_time | timestamp | 更新时间 | |
133+
134+ ``` mysql
135+ CREATE TABLE `tags ` (
136+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
137+ ` name` varchar (100 ) DEFAULT ' ' COMMENT ' 标签名称' ,
138+ ` count` int (4 ) DEFAULT ' 0' COMMENT ' 文章数量' ,
139+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
140+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
141+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
142+ PRIMARY KEY (` id` )
143+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章标签管理' ;
144+ ```
118145
119- ### 分类(Categories)
120146
121- | 字段 | 类型 | 说明 | 角色 |
147+
148+ ### 分类(categories)
149+
150+ | 字段 | 类型 | 说明 | 属性 |
122151| ---- | ---- | ---- | ---- |
123- | id | int | | 主键 |
124- | name | char | 分类名 | |
125- | count | int | 文章数量 | |
126- | create_timestamp | timestamp | 创建时间 | |
127- | update_timestamp | timestamp | 更新时间 | |
152+ | id | int(10) | | 主键 |
153+ | name | varchar(100) | 分类名 | |
154+ | count | int(10) | 文章数量 | |
155+ | create_time | timestamp | 创建时间 | |
156+ | update_time | timestamp | 更新时间 | |
157+
158+ ``` mysql
159+ CREATE TABLE `categories ` (
160+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
161+ ` name` varchar (100 ) DEFAULT ' ' COMMENT ' 分类名称' ,
162+ ` count` int (4 ) DEFAULT ' 0' COMMENT ' 文章数量' ,
163+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
164+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
165+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
166+ PRIMARY KEY (` id` )
167+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章分类管理' ;
168+ ```
169+
170+ ### 文章(articles)
171+
172+ | 字段 | 类型 | 说明 | 属性 |
173+ | ----------- | --------- | -------------- | ---- |
174+ | id | int | 不为空,自增长 | 主键 |
175+ | title | varchar | 标题 | |
176+ | tag_id | int(10) | 标签 | 外键 |
177+ | category_id | int(10) | 类别 | 外键 |
178+ | author_id | int(10) | 作者 | 外键 |
179+ | content | text | 正文 | |
180+ | update_time | timestamp | 更新时间 | |
181+ | create_time | timestamp | 发布时间 | |
182+ | delete_time | timestamp | 发布时间 | |
183+ | page_view | int(10) | 浏览量 | |
184+ | like_count | int(10) | 点赞数 | |
185+
186+ ``` mysql
187+ CREATE TABLE `articles ` (
188+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
189+ ` tag_id` int (10 ) unsigned COMMENT ' 标签ID' ,
190+ ` category_id` int (10 ) unsigned COMMENT ' 文章分类id' ,
191+ ` author_id` int (10 ) unsigned COMMENT ' 作者id' ,
192+ ` title` varchar (100 ) DEFAULT ' ' COMMENT ' 文章标题' ,
193+ ` content` text COMMENT ' 文章正文' ,
194+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
195+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
196+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
197+ ` page_view` int (10 ) unsigned DEFAULT ' 0' COMMENT ' 文章浏览量' ,
198+ ` like_count` int (10 ) unsigned DEFAULT ' 0' COMMENT ' 文章点赞数' ,
199+ PRIMARY KEY (` id` ),
200+ FOREIGN KEY (category_id) references categories(id),
201+ FOREIGN KEY (tag_id) references tags(id),
202+ FOREIGN KEY (author_id) references users(id)
203+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章管理' ;
204+ ```
205+
206+
128207
129- ### 评论(Comments)
208+ 由于有外键的约束,所以请先创建标签表和分类表后再执行文章表的创建
209+
210+ ``` mysql
211+
212+ CREATE TABLE `categories ` (
213+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
214+ ` name` varchar (100 ) DEFAULT ' ' COMMENT ' 分类名称' ,
215+ ` count` int (4 ) DEFAULT ' 0' COMMENT ' 文章数量' ,
216+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
217+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
218+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
219+ PRIMARY KEY (` id` )
220+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章分类管理' ;
221+
222+ CREATE TABLE `tags ` (
223+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
224+ ` name` varchar (100 ) DEFAULT ' ' COMMENT ' 标签名称' ,
225+ ` count` int (4 ) DEFAULT ' 0' COMMENT ' 文章数量' ,
226+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
227+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
228+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
229+ PRIMARY KEY (` id` )
230+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章标签管理' ;
231+
232+
233+ CREATE TABLE `users ` (
234+ ` id` int (10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
235+ ` name` varchar (100 ) NOT NULL COMMENT ' 用户名' ,
236+ ` passwd` VARCHAR (100 ) NOT NULL COMMENT ' 密码' ,
237+ ` email` VARCHAR (100 ) DEFAULT ' ' COMMENT ' 邮箱' ,
238+ ` profile_picture` VARCHAR (10 ) COMMENT ' 头像路径' ,
239+ ` last_login` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 最后登陆时间' ,
240+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
241+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 更新时间' ,
242+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
243+
244+ PRIMARY KEY (` id` )
245+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 用户管理' ;
246+
247+
248+ CREATE TABLE `articles ` (
249+ ` id` int (10 ) unsigned NOT NULL AUTO_INCREMENT,
250+ ` tag_id` int (10 ) unsigned COMMENT ' 标签ID' ,
251+ ` category_id` int (10 ) unsigned COMMENT ' 文章分类id' ,
252+ ` author_id` int (10 ) unsigned COMMENT ' 作者id' ,
253+ ` title` varchar (100 ) DEFAULT ' ' COMMENT ' 文章标题' ,
254+ ` content` text COMMENT ' 文章正文' ,
255+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
256+ ` update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 修改时间' ,
257+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
258+ ` page_view` int (10 ) unsigned DEFAULT ' 0' COMMENT ' 文章浏览量' ,
259+ ` like_count` int (10 ) unsigned DEFAULT ' 0' COMMENT ' 文章点赞数' ,
260+ PRIMARY KEY (` id` ),
261+ FOREIGN KEY (category_id) references categories(id),
262+ FOREIGN KEY (tag_id) references tags(id),
263+ FOREIGN KEY (author_id) references users(id)
264+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 文章管理' ;
265+ ```
266+
267+
268+
269+ 以下两个表,以后有需求再加入,现在暂不考虑
270+
271+
272+
273+ ### 评论(comments)
130274
131275| 字段 | 类型 | 说明 | 角色 |
132276| ---- | ---- | ---- | ---- |
133- | id | int | | 主键 |
134- | post_id | int | | 外键 |
135- | user_id | int | | 外键 |
277+ | id | int(10) | | 主键 |
278+ | post_in | int(10) | | 外键 |
279+ | created_by | int(10) | | 外键 |
136280| comment | text | 评论 | |
137- | create_timestamp | timestamp | 创建时间 | |
138- | update_timestamp | timestamp | 更新时间 | |
281+ | create_time | timestamp | 创建时间 | |
282+ | update_time | timestamp | 更新时间 | |
283+
284+ ``` mysql
285+ CREATE TABLE `comments ` (
286+ ` id` int (10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
287+ ` post_in` int (10 ) UNSIGNED COMMENT ' 文章id' ,
288+ ` created_by` int (10 ) UNSIGNED COMMENT ' 评论者id' ,
289+ ` comment` text COMMENT ' 评论内容' ,
290+ ` create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 创建时间' ,
291+ ` delete_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ' 删除时间' ,
292+ PRIMARY KEY (` id` ),
293+ FOREIGN KEY (` created_by` ) REFERENCES users(id),
294+ FOREIGN KEY (` post_in` ) REFERENCES articles(id)
295+ ) ENGINE= InnoDB DEFAULT CHARSET= utf8 COMMENT= ' 评论管理' ;
296+ ```
139297
140298
141- ### 用户(Users)
142299
143- | 字段 | 类型 | 说明 | 角色 |
144- | ---- | ---- | ---- | ---- |
145- | id | int | | 主键 |
146- | user | char | 用户名 | |
147- | passwd | char | 密码 | |
148- | email | char | 邮箱 | |
149- | profile_picture | char | 头像路径 | |
150- | last_login | timestamp | 最后登陆时间 | |
151- | create_timestamp | timestamp | 创建时间 | |
152- | update_timestamp | timestamp | 更新时间 | |
300+ ## 5. 接口整理
301+
302+ ### 文章
303+
304+ #### 新增文章
305+
306+ ##### Request
153307
308+ - Method: POST
309+ - URL: /v1.0/article
310+ - Headers: Content-Type: application /json
311+ - Body:
154312
313+ ``` json
314+ {
315+ "title" : " 如何从零开始学习 Golang ?" ,
316+ "tag" : " Golang" ,
317+ "category" : " Golang 学习" ,
318+ "author" : " 王炳明" ,
319+ "content" : " 正文"
320+ }
321+ ```
322+
323+ ##### Response
324+
325+ - Body
326+
327+ ``` json
328+ {
329+ "code" : 200 ,
330+ "message" : " OK"
331+ }
332+ ```
333+
334+
335+
336+ #### 删除文章
337+
338+ ##### Request
339+
340+ - Method: DELETE
341+ - URL: /v1.0/article
342+ - Headers: Content-Type: application /json
343+
344+ - Body:
345+
346+ ``` json
347+ {
348+ "id" : " 0001"
349+ }
350+ ```
351+
352+ ##### Response
353+
354+ ``` json
355+ {
356+ "code" : 200 ,
357+ "message" : " OK"
358+ }
359+ ```
155360
156- ## 5. 整理一下接口
157361
158- ### 文章(Posts)
159362
363+ #### 更新文章
160364
365+ ##### Request
161366
162- ### 评论(Comments)
367+ - Method: UPDATE
368+ - URL: /v1.0/article
369+ - Headers: Content-Type: application /json
163370
371+ - Body:
164372
373+ ``` json
374+ {
375+ "id" : " 0001" ,
376+ "title" : " 如何从零开始学习 Golang ?" ,
377+ "tag" : " Golang" ,
378+ "category" : " Golang 学习" ,
379+ "author" : " 王炳明" ,
380+ "content" : " 正文" ,
381+ }
382+ ```
383+
384+ ##### Response
385+
386+ ``` json
387+ {
388+ "code" : 200 ,
389+ "message" : " OK"
390+ }
391+ ```
165392
166- ### 用户(Users)
167393
168394
395+ ##
169396
170397## 6. 项目结构解析
171398
0 commit comments