From af9913c24c8aaaa1a6838867a79f9e28356c608f Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Thu, 2 Mar 2017 11:32:27 -0300 Subject: [PATCH] Translate routes corrections --- translate-api/controllers/translate.js | 21 ++++++++++++++++++++- translate-api/routes/translate.js | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/translate-api/controllers/translate.js b/translate-api/controllers/translate.js index 5b2ce48..88a0946 100644 --- a/translate-api/controllers/translate.js +++ b/translate-api/controllers/translate.js @@ -12,7 +12,7 @@ var shortid = require('shortid') , amqp = require('../helpers/amqpManager') , error = require('../helpers/error'); -exports.translate = function(req, res) { +exports.translate = function(req, res, next) { if (!req.body.text) return error.badRequest('The text key is missing.', next); @@ -29,3 +29,22 @@ exports.translate = function(req, res) { }); }); }; + +// TEMPORARY +exports.translateURL = function(req, res, next) { + if (!req.param('text')) + return error.badRequest('The text param is missing.', next); + + var id = shortid.generate(); + var text = req.param('text').toString('utf8'); + + amqp.sendToQueue(text, id,'texts', false, res, function(err) { + if (err) + return error.internalError('An internal communication error has occurred.', next); + amqp.receiveFromQueue(id, 'translations', false, res, function(err, message) { + if (err) + return error.internalError('An internal communication error has occurred.', next); + res.status(200).send(message); + }); + }); +}; diff --git a/translate-api/routes/translate.js b/translate-api/routes/translate.js index 246cf40..b12f76d 100644 --- a/translate-api/routes/translate.js +++ b/translate-api/routes/translate.js @@ -12,5 +12,6 @@ var express = require('express') */ router .post('/', translateController.translate) + .get('/', translateController.translateURL) // TEMPORARY module.exports = router; -- libgit2 0.21.2