Commit af9913c24c8aaaa1a6838867a79f9e28356c608f

Authored by Wesnydy Ribeiro
1 parent 974fcc3f

Translate routes corrections

translate-api/controllers/translate.js
... ... @@ -12,7 +12,7 @@ var shortid = require('shortid')
12 12 , amqp = require('../helpers/amqpManager')
13 13 , error = require('../helpers/error');
14 14  
15   -exports.translate = function(req, res) {
  15 +exports.translate = function(req, res, next) {
16 16 if (!req.body.text)
17 17 return error.badRequest('The text key is missing.', next);
18 18  
... ... @@ -29,3 +29,22 @@ exports.translate = function(req, res) {
29 29 });
30 30 });
31 31 };
  32 +
  33 +// TEMPORARY
  34 +exports.translateURL = function(req, res, next) {
  35 + if (!req.param('text'))
  36 + return error.badRequest('The text param is missing.', next);
  37 +
  38 + var id = shortid.generate();
  39 + var text = req.param('text').toString('utf8');
  40 +
  41 + amqp.sendToQueue(text, id,'texts', false, res, function(err) {
  42 + if (err)
  43 + return error.internalError('An internal communication error has occurred.', next);
  44 + amqp.receiveFromQueue(id, 'translations', false, res, function(err, message) {
  45 + if (err)
  46 + return error.internalError('An internal communication error has occurred.', next);
  47 + res.status(200).send(message);
  48 + });
  49 + });
  50 +};
... ...
translate-api/routes/translate.js
... ... @@ -12,5 +12,6 @@ var express = require('express')
12 12 */
13 13 router
14 14 .post('/', translateController.translate)
  15 + .get('/', translateController.translateURL) // TEMPORARY
15 16  
16 17 module.exports = router;
... ...