Skip to content

Commit

Permalink
feat(writeapi): topic tags
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Oct 8, 2020
1 parent 9be5629 commit 1605e5e
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 32 deletions.
137 changes: 132 additions & 5 deletions public/openapi/write.yaml
Expand Up @@ -590,7 +590,7 @@ paths:
type: object
properties: {}
/topics/{tid}/lock:
delete:
put:
tags:
- topics
summary: Lock a topic
Expand All @@ -608,7 +608,7 @@ paths:
response:
type: object
properties: {}
put:
delete:
tags:
- topics
summary: Unlock a topic
Expand All @@ -626,8 +626,8 @@ paths:
response:
type: object
properties: {}
/topics/{tid}/state:
delete:
/topics/{tid}/pin:
put:
tags:
- topics
summary: Pin a topic
Expand All @@ -645,7 +645,7 @@ paths:
response:
type: object
properties: {}
put:
delete:
tags:
- topics
summary: Unpin a topic
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/controllers/write/topics.js
Expand Up @@ -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]]');
Expand Down
29 changes: 2 additions & 27 deletions src/routes/write/topics.js
Expand Up @@ -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;
};

0 comments on commit 1605e5e

Please sign in to comment.