Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: find blueprint #9

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/blueprints/find.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Module dependencies
*/
var actionUtil = require('sails/lib/hooks/blueprints/actionUtil'),
localFind = require('sails/lib/hooks/blueprints/actions/find');

/**
* Find Records from FM API
*
* get /:modelIdentity
* * /:modelIdentity/find
*
* An API call to find and return model instances from the FM API.
* If in development, the local sails models will be queried instead
*
*/

module.exports = function findRecords (req, res) {

if (sails.config.environment === 'production') {

// Query FM API
fmAPI.get(req.url).on('complete', function (response) {
res.ok(response);
});

} else {

// Use mocked API through sails original find blueprint
return localFind(req, res);

}

};
18 changes: 1 addition & 17 deletions api/controllers/Player/queueController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,9 @@
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/

var rest = require('restler');

var FM = rest.service(function(u, p) {
this.defaults.username = u;
this.defaults.password = p;
}, {
baseURL: 'http://localdocker:5000'
}, {
update: function(track) {
return this.put('/player/queue', track);
}
});

module.exports = {
find: function (req, res) {
var fm = new FM('', '');
fm.get(req.url).on('complete', function (response) {
res.send(response);
});
}

};

25 changes: 25 additions & 0 deletions api/services/fmAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
/**
* Module dependencies
*/
var rest = require('restler');

/**
* FM API Service
*
* @description :: Service for communicating with FM API
*/


var FM = rest.service(function(u, p) {
this.defaults.username = u;
this.defaults.password = p;
}, {
baseURL: 'http://localdocker:5000'
}, {
update: function(track) {
return this.put('/player/queue', track);
}
});

module.exports = new fmAPI('', '');
2 changes: 1 addition & 1 deletion config/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports.models = {
* connections (see `config/connections.js`) *
* *
***************************************************************************/
// connection: 'localDiskDb',
connection: 'localDiskDb',

/***************************************************************************
* *
Expand Down
2 changes: 1 addition & 1 deletion config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports.routes = {
'/': {
view: 'homepage'
},
'GET /player/queue*': 'Player/queueController.find'
'GET /player/queue*': { blueprint: 'find', model: 'queue' }

/***************************************************************************
* *
Expand Down