Skip to content

Commit d7b5d9f

Browse files
feat: 新增更新访问量的接口
1 parent ef3faea commit d7b5d9f

File tree

2 files changed

+104
-27
lines changed

2 files changed

+104
-27
lines changed

service/app/controller/blog/articledetail.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'use strict';
1+
"use strict";
22

3-
const controller = require('egg').Controller;
3+
const controller = require("egg").Controller;
44
class ArticleDetailController extends controller {
55
async getArticleDetailById() {
66
const id = this.ctx.params.id;
@@ -19,7 +19,7 @@ class ArticleDetailController extends controller {
1919
LEFT JOIN article_type as type
2020
ON article.type_id = type.id
2121
WHERE article.id = ? AND article.is_publish = 1`;
22-
const result = await this.app.mysql.query(sql, [ id ]);
22+
const result = await this.app.mysql.query(sql, [id]);
2323
if (result.length > 0) {
2424
this.ctx.body = {
2525
success: true,
@@ -28,7 +28,26 @@ class ArticleDetailController extends controller {
2828
} else {
2929
this.ctx.body = {
3030
success: false,
31-
message: '获取文章详情失败',
31+
message: "获取文章详情失败",
32+
};
33+
}
34+
}
35+
36+
async addArticleViewCountById() {
37+
const id = this.ctx.params.id;
38+
const sql = `UPDATE
39+
article
40+
SET view_count = view_count + 1
41+
WHERE article.id = ? AND article.is_publish = 1`;
42+
const result = await this.app.mysql.query(sql, [id]);
43+
if (result.length > 0) {
44+
this.ctx.body = {
45+
success: true,
46+
};
47+
} else {
48+
this.ctx.body = {
49+
success: false,
50+
message: "更新文章访问量失败",
3251
};
3352
}
3453
}

service/app/router/blog.js

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,84 @@
1-
'use strict';
1+
"use strict";
22

3-
module.exports = app => {
3+
module.exports = (app) => {
44
const { router, controller } = app;
5-
router.post('/api/blog/comment/visitorLogin', controller.blog.comment.visitorLogin);
6-
router.post('/api/blog/comment/updatePortrait', controller.blog.comment.updatePortrait);
7-
router.post('/api/blog/upload', controller.blog.upload.index);
8-
router.post('/api/blog/comment/getComments', controller.blog.comment.getComments);
9-
router.post('/api/blog/comment/addComment', controller.blog.comment.addComment);
10-
router.post('/api/blog/comment/addLikeCount', controller.blog.comment.addLikeCount);
11-
router.post('/api/blog/index/getTalkList', controller.blog.index.getTalkList);
12-
router.post('/api/blog/index/addLikeCount', controller.blog.index.addLikeCount);
13-
router.get('/api/blog/index/getUserInfoById/:id', controller.blog.index.getUserInfoById);
14-
router.post('/api/blog/index/getArticleList', controller.blog.index.getArticleList);
15-
router.get('/api/blog/index/getAdverList', controller.blog.index.getAdverList);
16-
router.get('/api/blog/articledetail/getArticleDetailById/:id', controller.blog.articledetail.getArticleDetailById);
17-
router.post('/api/blog/articlelist/getArticleList', controller.blog.articlelist.getArticleList);
18-
router.get('/api/blog/articlelist/getArticleTypes', controller.blog.articlelist.getArticleTypes);
19-
router.get('/api/blog/about/getAbout', controller.blog.about.getAbout);
20-
router.post('/api/blog/index/getNovelList', controller.blog.index.getNovelList);
21-
router.get('/api/blog/novel/getChapterById/:id', controller.blog.novel.getChapterById);
22-
router.get('/api/blog/novel/getNovelById/:id', controller.blog.novel.getNovelById);
23-
router.get('/api/blog/novel/getChapterListById/:id', controller.blog.novel.getChapterListById);
24-
router.post('/api/blog/index/getIndexListApp', controller.blog.index.getIndexListApp);
25-
router.post('/api/blog/index/getSearchList', controller.blog.index.getSearchList);
5+
router.post(
6+
"/api/blog/comment/visitorLogin",
7+
controller.blog.comment.visitorLogin
8+
);
9+
router.post(
10+
"/api/blog/comment/updatePortrait",
11+
controller.blog.comment.updatePortrait
12+
);
13+
router.post("/api/blog/upload", controller.blog.upload.index);
14+
router.post(
15+
"/api/blog/comment/getComments",
16+
controller.blog.comment.getComments
17+
);
18+
router.post(
19+
"/api/blog/comment/addComment",
20+
controller.blog.comment.addComment
21+
);
22+
router.post(
23+
"/api/blog/comment/addLikeCount",
24+
controller.blog.comment.addLikeCount
25+
);
26+
router.post("/api/blog/index/getTalkList", controller.blog.index.getTalkList);
27+
router.post(
28+
"/api/blog/index/addLikeCount",
29+
controller.blog.index.addLikeCount
30+
);
31+
router.get(
32+
"/api/blog/index/getUserInfoById/:id",
33+
controller.blog.index.getUserInfoById
34+
);
35+
router.post(
36+
"/api/blog/index/getArticleList",
37+
controller.blog.index.getArticleList
38+
);
39+
router.get(
40+
"/api/blog/index/getAdverList",
41+
controller.blog.index.getAdverList
42+
);
43+
router.get(
44+
"/api/blog/articledetail/getArticleDetailById/:id",
45+
controller.blog.articledetail.getArticleDetailById
46+
);
47+
router.get(
48+
"/api/blog/articledetail/addArticleViewCountById/:id",
49+
controller.blog.articledetail.addArticleViewCountById
50+
);
51+
router.post(
52+
"/api/blog/articlelist/getArticleList",
53+
controller.blog.articlelist.getArticleList
54+
);
55+
router.get(
56+
"/api/blog/articlelist/getArticleTypes",
57+
controller.blog.articlelist.getArticleTypes
58+
);
59+
router.get("/api/blog/about/getAbout", controller.blog.about.getAbout);
60+
router.post(
61+
"/api/blog/index/getNovelList",
62+
controller.blog.index.getNovelList
63+
);
64+
router.get(
65+
"/api/blog/novel/getChapterById/:id",
66+
controller.blog.novel.getChapterById
67+
);
68+
router.get(
69+
"/api/blog/novel/getNovelById/:id",
70+
controller.blog.novel.getNovelById
71+
);
72+
router.get(
73+
"/api/blog/novel/getChapterListById/:id",
74+
controller.blog.novel.getChapterListById
75+
);
76+
router.post(
77+
"/api/blog/index/getIndexListApp",
78+
controller.blog.index.getIndexListApp
79+
);
80+
router.post(
81+
"/api/blog/index/getSearchList",
82+
controller.blog.index.getSearchList
83+
);
2684
};

0 commit comments

Comments
 (0)