diff --git a/common/script/index.coffee b/common/script/index.coffee index 3566f5db79..4ed93b832a 100644 --- a/common/script/index.coffee +++ b/common/script/index.coffee @@ -673,6 +673,14 @@ api.wrap = (user, main=true) -> user.tags.splice to, 0, user.tags.splice(from, 1)[0] cb? null, user.tags + getTags: (req, cb) -> + cb? null, user.tags + + getTag: (req, cb) -> + tid = req.params.id + i = _.findIndex user.tags, {id: tid} + return cb?({code:404,message:i18n.t('messageTagNotFound', req.language)}) if !~i + cb? null, user.tags[i] updateTag: (req, cb) -> tid = req.params.id diff --git a/test/api/user/GET-user_tags.test.js b/test/api/user/GET-user_tags.test.js new file mode 100644 index 0000000000..c76d5f66e4 --- /dev/null +++ b/test/api/user/GET-user_tags.test.js @@ -0,0 +1,20 @@ +import { + generateUser, + requester, +} from '../../helpers/api.helper'; + +describe('GET /user/tags', () => { + let api, user; + + beforeEach(() => { + return generateUser().then((usr) => { + user = usr; + api = requester(usr); + }); + }); + + it('gets the user\'s tags', () => { + return expect(api.get('/user/tags')) + .to.eventually.eql(user.tags); + }); +}); diff --git a/test/api/user/GET-user_tags_id.test.js b/test/api/user/GET-user_tags_id.test.js new file mode 100644 index 0000000000..9fdf2f0caa --- /dev/null +++ b/test/api/user/GET-user_tags_id.test.js @@ -0,0 +1,25 @@ +import { + generateUser, + requester, +} from '../../helpers/api.helper'; + +describe('GET /user/tags/id', () => { + let api, user; + + beforeEach(() => { + return generateUser().then((usr) => { + user = usr; + api = requester(usr); + }); + }); + + it('gets a user\'s tag by id', () => { + return expect(api.get('/user/tags/' + user.tags[0].id)) + .to.eventually.eql(user.tags[0]); + }); + + it('fails for non-existent tags', () => { + return expect(api.get('/user/tags/not-an-id')) + .to.eventually.be.rejected.with.property('code', 404); + }); +}); diff --git a/website/src/routes/apiv2.coffee b/website/src/routes/apiv2.coffee index 5a6aba7a49..8edc2277aa 100644 --- a/website/src/routes/apiv2.coffee +++ b/website/src/routes/apiv2.coffee @@ -347,8 +347,19 @@ module.exports = (swagger, v2) -> action: user.batchUpdate # Tags - "/user/tags": + "/user/tags/{id}:GET": spec: + path: '/user/tags/{id}' + method: 'GET' + description: "Get a tag" + parameters: [ + path 'id','The id of the tag to get','string' + ] + action: user.getTag + + "/user/tags:POST": + spec: + path: "/user/tags" method: 'POST' description: 'Create a new tag' parameters: [ @@ -356,6 +367,13 @@ module.exports = (swagger, v2) -> ] action: user.addTag + "/user/tags:GET": + spec: + path: "/user/tags" + method: 'GET' + description: 'List all of a user\'s tags' + action: user.getTags + "/user/tags/sort": spec: method: 'POST'