Browse Source

Add Tag API

master
sipp11 9 years ago
parent
commit
de5acb5cba
  1. 54
      api/controllers/TagController.js
  2. 20
      api/models/Tag.js
  3. 4
      config/env/development/connections.js
  4. 3
      config/routes.js

54
api/controllers/TagController.js

@ -0,0 +1,54 @@
/**
* TagController
*
* @description :: Server-side logic for managing Tags
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
module.exports = {
list: function(req, res) {
var team = req.param('team'),
type = req.query.type,
format = req.query.format,
q = {
where: { team: team },
sort: { name: 1 }
};
if (type != undefined)
q['where'] = {
$and: [
{ team: team },
{ relatedTo: { $in: [type] } }
]
}
page = ((req.query.page != undefined) ? +req.query.page : 1);
Tag.find(q).paginate({page: page, limit: 10}).exec(function(err, items) {
if (format == 'long') {
res.send(items);
} else {
var tags = [];
for (var ind in items) {
tags.push(items[ind].name);
}
res.send(tags);
}
});
},
detail: function(req, res) {
var team = req.param('team'),
name = req.param('name');
Tag.findOne({team: team, name: name}).exec(function(err, item) {
if (item == undefined)
res.send({});
else
res.send(item);
});
}
};

20
api/models/Tag.js

@ -0,0 +1,20 @@
/**
* Tag.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
connection: 'jarvisBlackboard',
attributes: {
team: 'string',
name: 'string',
relatedTo: {
type: 'array'
}
}
};

4
config/env/development/connections.js vendored

@ -2,7 +2,7 @@ module.exports.connections = {
hackintoshMongo: {
adapter: 'sails-mongo',
host: '10hackintosh',
host: '10.10.10.51',
port: 27017,
// user: 'username',
// password: 'password',
@ -10,7 +10,7 @@ module.exports.connections = {
},
jarvisBlackboard: {
adapter: 'sails-mongo',
host: '10hackintosh',
host: '10.10.10.51',
port: 27017,
// user: 'username',
// password: 'password',

3
config/routes.js

@ -58,4 +58,7 @@ module.exports.routes = {
'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid',
'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi',
'GET /tag/:team': 'TagController.list',
'GET /tag/:team/:name': 'TagController.detail',
};

Loading…
Cancel
Save