Skip to content

Node.js based forum software built for the modern web

feat(writeapi): topic tags

Julian Lam1605e5e44343
diff --git a/public/openapi/write.yaml b/public/openapi/write.yaml
index 224eafd53d..fa4834da55 100644
--- a/public/openapi/write.yaml
+++ b/public/openapi/write.yaml
@@ -590,7 +590,7 @@ paths:
type: object
properties: {}
/topics/{tid}/lock:
- delete:
+ put:
tags:
- topics
summary: Lock a topic
@@ -608,7 +608,7 @@ paths:
response:
type: object
properties: {}
- put:
+ delete:
tags:
- topics
summary: Unlock a topic
@@ -626,8 +626,8 @@ paths:
response:
type: object
properties: {}
- /topics/{tid}/state:
- delete:
+ /topics/{tid}/pin:
+ put:
tags:
- topics
summary: Pin a topic
@@ -645,7 +645,7 @@ paths:
response:
type: object
properties: {}
- put:
+ delete:
tags:
- topics
summary: Unpin a topic
@@ -663,6 +663,133 @@ paths:
response:
type: object
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:
schemas:
Status:
diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.js
index c90dadfef0..0b5471f6ab 100644
--- a/src/controllers/write/topics.js
+++ b/src/controllers/write/topics.js
@@ -138,6 +138,16 @@ Topics.unfollow = async (req, 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 }) {
if (!Array.isArray(tids)) {
throw new Error('[[error:invalid-tid]]');
diff --git a/src/routes/write/topics.js b/src/routes/write/topics.js
index 6e11b5a8e9..5c25b4acd2 100644
--- a/src/routes/write/topics.js
+++ b/src/routes/write/topics.js
@@ -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], 'delete', controllers.write.topics.unfollow); // intentional, unignore == unfollow
- // app.route('/:tid/follow')
- // .put(apiMiddleware.requireUser, apiMiddleware.validateTid, function(req, res) {
- // 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);
- // });
- // });
+ setupApiRoute(router, '/:tid/tags', middleware, [...middlewares, middleware.checkRequired.bind(null, ['tags']), middleware.assertTopic], 'put', controllers.write.topics.addTags);
+ setupApiRoute(router, '/:tid/tags', middleware, [...middlewares, middleware.assertTopic], 'delete', controllers.write.topics.deleteTags);
return router;
};