11/**
2- * @Controller
3- * @Module topics
4- * ---------------------------------------------
52 * Author : IndexXuan(https://github.com/IndexXuan)
63 * Mail : indexxuan@gmail.com
74 * Date : Fri 03 Mar 2017 03:23:34 PM CST
85 */
96
107/**
11- * @Controller
12- *
13- * 1. 调用validate方法对请求参数进行验证
14- * 2. 按照接口约定的格式设置响应状态码和内容
8+ * @Controller
9+ * @file 主题相关API
10+ * @author IndexXuan
11+ * @module Topics
1512 */
1613
1714'use strict'
1815
1916module . exports = app => {
2017 return class TopicsController extends app . Controller {
2118 /**
22- * latest
23- * 返回最新topics
19+ * 返回最新topics列表
20+ * @example
21+ * GET /api/v2/topics/latest
2422 *
25- * @param {Object } ctx - 请求上下文
26- * @returns {Promise } - @async
23+ * [{
24+ * id: 350959,
25+ * url: "http://www.v2ex.com/t/350959",
26+ * title: "MacBook Pro 13 寸顶配 最新款转让",
27+ * replies: 1,
28+ * content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
29+ * created: 1490693527,
30+ * member: {
31+ * id: 79264,
32+ * username: "richardzhou",
33+ * vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
34+ * avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
35+ * avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
36+ * tagline: ""
37+ * },
38+ * node: {
39+ * id: 10,
40+ * name: "mbp",
41+ * title: "MacBook Pro",
42+ * title_alternative: "MacBook Pro",
43+ * topics: 3021,
44+ * url: "http://www.v2ex.com/go/mbp",
45+ * avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
46+ * avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
47+ * avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
48+ * },
49+ * last_modified: 1490693527,
50+ * last_touched: 1490693347
51+ * }, {
52+ * ...
53+ * }]
2754 */
28- async latest ( ctx ) {
55+ async latest ( ) {
56+ const { ctx } = this
2957 ctx . body = await ctx . service . topics . latest ( )
3058 }
3159
3260 /**
33- * hot
34- * 返回最热topics
61+ * 返回最热topics列表
62+ * @example
63+ * GET /api/v2/topics/hot
3564 *
36- * @param {Object } ctx - 请求上下文
37- * @returns {Promise } - @async
65+ * [{
66+ * id: 350959,
67+ * url: "http://www.v2ex.com/t/350959",
68+ * title: "MacBook Pro 13 寸顶配 最新款转让",
69+ * replies: 1,
70+ * content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
71+ * created: 1490693527,
72+ * member: {
73+ * id: 79264,
74+ * username: "richardzhou",
75+ * vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
76+ * avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
77+ * avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
78+ * tagline: ""
79+ * },
80+ * node: {
81+ * id: 10,
82+ * name: "mbp",
83+ * title: "MacBook Pro",
84+ * title_alternative: "MacBook Pro",
85+ * topics: 3021,
86+ * url: "http://www.v2ex.com/go/mbp",
87+ * avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
88+ * avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
89+ * avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
90+ * },
91+ * last_modified: 1490693527,
92+ * last_touched: 1490693347
93+ * }, {
94+ * ...
95+ * }]
3896 */
39- async hot ( ctx ) {
97+ async hot ( ) {
98+ const { ctx } = this
4099 ctx . body = await ctx . service . topics . hot ( )
41100 }
42101
43102 /**
44- * show
45- * 返回一个特定topics
103+ * 返回特定topics
104+ * @param {Number|String } id - topic_id
105+ * @example
106+ * GET /api/v2/topics/show?id=${id}
46107 *
47- * @param {Object } ctx - 请求上下文
48- * @returns {Promise }-@async
108+ * {
109+ * id: 350959,
110+ * url: "http://www.v2ex.com/t/350959",
111+ * title: "MacBook Pro 13 寸顶配 最新款转让",
112+ * replies: 1,
113+ * content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
114+ * created: 1490693527,
115+ * member: {
116+ * id: 79264,
117+ * username: "richardzhou",
118+ * vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
119+ * avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
120+ * avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
121+ * tagline: ""
122+ * },
123+ * node: {
124+ * id: 10,
125+ * name: "mbp",
126+ * title: "MacBook Pro",
127+ * title_alternative: "MacBook Pro",
128+ * topics: 3021,
129+ * url: "http://www.v2ex.com/go/mbp",
130+ * avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
131+ * avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
132+ * avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
133+ * },
134+ * last_modified: 1490693527,
135+ * last_touched: 1490693347
136+ * }
49137 */
50- async show ( ctx ) {
138+ async show ( ) {
139+ const { ctx } = this
51140 // validator
52141 ctx . validate ( {
53142 id : { type : 'id' , required : true }
@@ -57,14 +146,47 @@ module.exports = app => {
57146 }
58147
59148 /**
60- * getAllByType
61149 * 返回一个类型下的所有topics
62- * @enums : [ 'username', 'node_name', 'node_id' ]
150+ * @param {String } type - topics的类型
151+ * - @enum [ 'username', 'node_name', 'node_id' ]
152+ * @param {String } value - topics类型的值
153+ * @example
154+ * GET /api/v2/topics/node_name/vim
63155 *
64- * @param {Object } ctx - 请求上下文
65- * @returns {Promise }-@async
156+ * [{
157+ * id: 350959,
158+ * url: "http://www.v2ex.com/t/350959",
159+ * title: "MacBook Pro 13 寸顶配 最新款转让",
160+ * replies: 1,
161+ * content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
162+ * created: 1490693527,
163+ * member: {
164+ * id: 79264,
165+ * username: "richardzhou",
166+ * vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
167+ * avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
168+ * avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
169+ * tagline: ""
170+ * },
171+ * node: {
172+ * id: 10,
173+ * name: "mbp",
174+ * title: "MacBook Pro",
175+ * title_alternative: "MacBook Pro",
176+ * topics: 3021,
177+ * url: "http://www.v2ex.com/go/mbp",
178+ * avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
179+ * avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
180+ * avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
181+ * },
182+ * last_modified: 1490693527,
183+ * last_touched: 1490693347
184+ * }, {
185+ * ...
186+ * }]
66187 */
67- async getAllByType ( ctx ) {
188+ async getAllByType ( ) {
189+ const { ctx } = this
68190 // validator
69191 ctx . validate ( {
70192 type : { type : 'enum' , values : [ 'username' , 'node_name' , 'node_id' ] , required : true } ,
@@ -78,13 +200,23 @@ module.exports = app => {
78200 }
79201
80202 /**
81- * create
82203 * 创建一个topic,返回创建结果
83204 *
84- * @param ctx
85- * @returns {Promise } - @async
205+ * @param {String } title - 标题
206+ * @param {String } content - 内容
207+ * @param {String } node_name - 节点名
208+ * @example
209+ * POST /api/v2/topics/new
210+ * data: { title: ${title}, content: ${content}, node_name: ${node_name} }
211+ *
212+ * {
213+ * result: true|false,
214+ * msg: ${msg}, // 可能的一些信息
215+ * url: ${url} // 此新建topic的url
216+ * }
86217 */
87- async create ( ctx ) {
218+ async create ( ) {
219+ const { ctx } = this
88220 ctx . validate ( {
89221 title : { type : 'string' , required : true } ,
90222 content : { type : 'string' , required : true } ,
0 commit comments