mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
feat(writeapi): topic tags
This commit is contained in:
@@ -590,7 +590,7 @@ paths:
|
|||||||
type: object
|
type: object
|
||||||
properties: {}
|
properties: {}
|
||||||
/topics/{tid}/lock:
|
/topics/{tid}/lock:
|
||||||
delete:
|
put:
|
||||||
tags:
|
tags:
|
||||||
- topics
|
- topics
|
||||||
summary: Lock a topic
|
summary: Lock a topic
|
||||||
@@ -608,7 +608,7 @@ paths:
|
|||||||
response:
|
response:
|
||||||
type: object
|
type: object
|
||||||
properties: {}
|
properties: {}
|
||||||
put:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- topics
|
- topics
|
||||||
summary: Unlock a topic
|
summary: Unlock a topic
|
||||||
@@ -626,8 +626,8 @@ paths:
|
|||||||
response:
|
response:
|
||||||
type: object
|
type: object
|
||||||
properties: {}
|
properties: {}
|
||||||
/topics/{tid}/state:
|
/topics/{tid}/pin:
|
||||||
delete:
|
put:
|
||||||
tags:
|
tags:
|
||||||
- topics
|
- topics
|
||||||
summary: Pin a topic
|
summary: Pin a topic
|
||||||
@@ -645,7 +645,7 @@ paths:
|
|||||||
response:
|
response:
|
||||||
type: object
|
type: object
|
||||||
properties: {}
|
properties: {}
|
||||||
put:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- topics
|
- topics
|
||||||
summary: Unpin a topic
|
summary: Unpin a topic
|
||||||
@@ -663,6 +663,133 @@ paths:
|
|||||||
response:
|
response:
|
||||||
type: object
|
type: object
|
||||||
properties: {}
|
properties: {}
|
||||||
|
/topics/{tid}/follow:
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Follow a topic
|
||||||
|
description: This operation follows (or watches) a topic.
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic successfully followed
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Unfollow a topic
|
||||||
|
description: This operation unfollows (or unwatches) a topic.
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic successfully unwatched
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
/topics/{tid}/ignore:
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Ignore a topic
|
||||||
|
description: This operation ignores (or watches) a topic.
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic successfully ignored
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Unignore a topic
|
||||||
|
description: This operation unignores (or unfollows/unwatches) a topic. It is functionally identical to `DEL /topics/{tid}/follow`.
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic successfully unignored/unwatched
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
/topics/{tid}/tags:
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Adds tags to a topic
|
||||||
|
description: This operation adds tags to a topic
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
description: 'An array of tags'
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example:
|
||||||
|
tags:
|
||||||
|
- test
|
||||||
|
- foobar
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic tags successfully added
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- topics
|
||||||
|
summary: Removes all tags from a topic
|
||||||
|
description: This operation removed all tags associated with a topic.
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Topic tags successfully removed.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
Status:
|
Status:
|
||||||
|
|||||||
@@ -138,6 +138,16 @@ Topics.unfollow = async (req, res) => {
|
|||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.addTags = async (req, res) => {
|
||||||
|
await topics.createTags(req.body.tags, req.params.tid, Date.now());
|
||||||
|
helpers.formatApiResponse(200, res);
|
||||||
|
};
|
||||||
|
|
||||||
|
Topics.deleteTags = async (req, res) => {
|
||||||
|
await topics.deleteTopicTags(req.params.tid);
|
||||||
|
helpers.formatApiResponse(200, res);
|
||||||
|
};
|
||||||
|
|
||||||
async function doTopicAction(action, event, socket, { tids }) {
|
async function doTopicAction(action, event, socket, { tids }) {
|
||||||
if (!Array.isArray(tids)) {
|
if (!Array.isArray(tids)) {
|
||||||
throw new Error('[[error:invalid-tid]]');
|
throw new Error('[[error:invalid-tid]]');
|
||||||
|
|||||||
@@ -28,33 +28,8 @@ module.exports = function () {
|
|||||||
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'put', controllers.write.topics.ignore);
|
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'put', controllers.write.topics.ignore);
|
||||||
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.unfollow); // intentional, unignore == unfollow
|
setupApiRoute(router, '/:tid/ignore', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.unfollow); // intentional, unignore == unfollow
|
||||||
|
|
||||||
// app.route('/:tid/follow')
|
setupApiRoute(router, '/:tid/tags', middleware, [...middlewares, middleware.checkRequired.bind(null, ['tags']), middleware.assertTopic], 'put', controllers.write.topics.addTags);
|
||||||
// .put(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
|
setupApiRoute(router, '/:tid/tags', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.deleteTags);
|
||||||
// Topics.follow(req.params.tid, req.user.uid, function(err) {
|
|
||||||
// errorHandler.handle(err, res);
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .delete(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
|
|
||||||
// Topics.unfollow(req.params.tid, req.user.uid, function(err) {
|
|
||||||
// errorHandler.handle(err, res);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.route('/:tid/tags')
|
|
||||||
// .put(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
|
|
||||||
// if (!utils.checkRequired(['tags'], req, res)) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Topics.createTags(req.body.tags, req.params.tid, Date.now(), function(err) {
|
|
||||||
// errorHandler.handle(err, res);
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .delete(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
|
|
||||||
// Topics.deleteTopicTags(req.params.tid, function(err) {
|
|
||||||
// errorHandler.handle(err, res);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user