Commit 37a877c0962f5fcbeae898c53c853f685f16d4a5
1 parent
d50f6c33
Exists in
master
Adiantamento na API do Wikilibras
Showing
14 changed files
with
343 additions
and
5 deletions
Show diff stats
| @@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
| 1 | +function read_all(Sign, callback) { | ||
| 2 | + Sign.find(function(err, signs) { | ||
| 3 | + if (err) callback(null); | ||
| 4 | + | ||
| 5 | + callback(signs); | ||
| 6 | + }); | ||
| 7 | +}; | ||
| 8 | + | ||
| 9 | +function create(object, callback) { | ||
| 10 | + object.save(function(err, sign) { | ||
| 11 | + if (err) callback(null); | ||
| 12 | + | ||
| 13 | + callback(sign); | ||
| 14 | + }); | ||
| 15 | +}; | ||
| 16 | + | ||
| 17 | +function remove(Sign, hash, callback) { | ||
| 18 | + Sign.remove({ uuid: hash }, function(err, sign) { | ||
| 19 | + if (err) callback(null); | ||
| 20 | + | ||
| 21 | + callback(sign); | ||
| 22 | + }); | ||
| 23 | +}; | ||
| 24 | + | ||
| 25 | +module.exports.read_all = read_all; | ||
| 26 | +module.exports.create = create; | ||
| 27 | +module.exports.remove = remove; | ||
| 0 | \ No newline at end of file | 28 | \ No newline at end of file |
| @@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
| 1 | +function connectMongo(mongoose) { | ||
| 2 | + var db = mongoose.connection; | ||
| 3 | + | ||
| 4 | + db.on('error', console.error); | ||
| 5 | + db.once('open', function() { | ||
| 6 | + console.log('Conectado ao MongoDB.') | ||
| 7 | + }); | ||
| 8 | + | ||
| 9 | + mongoose.connect('mongodb://localhost/wikilibras-api'); | ||
| 10 | +}; | ||
| 11 | + | ||
| 12 | +module.exports.connect = connectMongo; | ||
| 0 | \ No newline at end of file | 13 | \ No newline at end of file |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +function init_schema(mongoose) { | ||
| 2 | + var signSchema = new mongoose.Schema({ | ||
| 3 | + name: String, | ||
| 4 | + uuid: String, | ||
| 5 | + status: String, | ||
| 6 | + created_at: { type: Date }, | ||
| 7 | + updated_at: { type: Date } | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + var Sign = mongoose.model('Sign', signSchema); | ||
| 11 | + | ||
| 12 | + return Sign; | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +module.exports.init = init_schema; | ||
| 0 | \ No newline at end of file | 16 | \ No newline at end of file |
endpoints/sinal.js
| 1 | -function initEndpoint(req, res) { | ||
| 2 | - res.send(200, { 'status': 'Estrutura Montada :)'}); | 1 | +var uuid = require('node-uuid'); |
| 2 | +var API = require('../db/api'); | ||
| 3 | + | ||
| 4 | +function init_endpoint(req, res, Sign) { | ||
| 5 | + /* Verifica se o paramêtro [name] existe ou possui algum valor */ | ||
| 6 | + if ((req.body.name === '') || (req.body.name === undefined)) { | ||
| 7 | + res.send(500, { 'error': 'Especifique o nome do sinal' }); | ||
| 8 | + return; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + var array = ['Sucesso', 'Falhou', 'Processando'] | ||
| 12 | + | ||
| 13 | + var sign_object = new Sign({ | ||
| 14 | + name: req.body.name, | ||
| 15 | + uuid: uuid.v4(), | ||
| 16 | + created_at: new Date(), | ||
| 17 | + updated_at: new Date(), | ||
| 18 | + status: array[Math.floor(Math.random() * array.length)] | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + API.create(sign_object, function(result) { | ||
| 22 | + if (result !== null) { | ||
| 23 | + res.send(200, { 'status': 'Sinal ' + result.name + ' criado com sucesso'}); | ||
| 24 | + } else { | ||
| 25 | + res.send(500, { 'error': 'Erro na criação.'}); | ||
| 26 | + } | ||
| 27 | + }); | ||
| 3 | }; | 28 | }; |
| 4 | 29 | ||
| 5 | -module.exports.init = initEndpoint; | ||
| 6 | \ No newline at end of file | 30 | \ No newline at end of file |
| 31 | +module.exports.init = init_endpoint; | ||
| 32 | + |
package.json
public/assets/css/.sass-cache/b8ff95717abe9141bb02c85d4daf286641f59094/main.scssc
0 → 100644
No preview for this file type
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +body { | ||
| 2 | + margin: 0; | ||
| 3 | + padding: 0; } | ||
| 4 | + | ||
| 5 | +header { | ||
| 6 | + width: 100%; | ||
| 7 | + height: 60px; | ||
| 8 | + box-shadow: 1px 1px 2px #c2c2c2; } | ||
| 9 | + header > p { | ||
| 10 | + -webkit-font-smoothing: antialiased; | ||
| 11 | + text-align: center; | ||
| 12 | + position: relative; | ||
| 13 | + top: 13px; | ||
| 14 | + font-family: 'Open Sans Light',X-LocaleSpecific-Light,'Open Sans',X-LocaleSpecific,sans-serif; | ||
| 15 | + font-weight: normal; | ||
| 16 | + line-height: 100%; | ||
| 17 | + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75); | ||
| 18 | + color: #484848; | ||
| 19 | + font-size: 30px; } | ||
| 20 | + | ||
| 21 | +.main-container { | ||
| 22 | + width: 100%; | ||
| 23 | + display: table; } | ||
| 24 | + .main-container .table-wl { | ||
| 25 | + width: 70%; | ||
| 26 | + margin: 0 auto; | ||
| 27 | + margin-top: 40px; } | ||
| 28 | + .main-container .table-wl tbody tr ._success { | ||
| 29 | + color: #85D42A; | ||
| 30 | + font-weight: bold; } | ||
| 31 | + .main-container .table-wl tbody tr ._error { | ||
| 32 | + color: red; | ||
| 33 | + font-weight: bold; } | ||
| 34 | + .main-container .table-wl tbody tr ._processing { | ||
| 35 | + color: #c2c2c2; | ||
| 36 | + font-weight: bold; } | ||
| 37 | + | ||
| 38 | +/*# sourceMappingURL=main.css.map */ |
| @@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
| 1 | +{ | ||
| 2 | +"version": 3, | ||
| 3 | +"mappings": "AAAA,IAAK;EACJ,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;;AAGX,MAAO;EACN,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,mBAAmB;EAE/B,UAAI;IACH,sBAAsB,EAAE,WAAW;IACnC,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,QAAQ;IAClB,GAAG,EAAE,IAAI;IACT,WAAW,EAAE,gFAAgF;IAC7F,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,iCAA8B;IAC3C,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,IAAI;;AAIjB,eAAgB;EACf,KAAK,EAAE,IAAI;EACX,OAAO,EAAE,KAAK;EAEd,yBAAU;IACT,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,IAAI;IAId,4CAAU;MACT,KAAK,EAAE,OAAO;MACd,WAAW,EAAE,IAAI;IAGlB,0CAAQ;MACP,KAAK,EAAE,GAAG;MACV,WAAW,EAAE,IAAI;IAGlB,+CAAa;MACZ,KAAK,EAAE,OAAO;MACd,WAAW,EAAE,IAAI", | ||
| 4 | +"sources": ["main.scss"], | ||
| 5 | +"names": [], | ||
| 6 | +"file": "main.css" | ||
| 7 | +} | ||
| 0 | \ No newline at end of file | 8 | \ No newline at end of file |
| @@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
| 1 | +body { | ||
| 2 | + margin: 0; | ||
| 3 | + padding: 0; | ||
| 4 | +} | ||
| 5 | + | ||
| 6 | +header { | ||
| 7 | + width: 100%; | ||
| 8 | + height: 60px; | ||
| 9 | + box-shadow: 1px 1px 2px #c2c2c2; | ||
| 10 | + | ||
| 11 | + > p { | ||
| 12 | + -webkit-font-smoothing: antialiased; | ||
| 13 | + text-align: center; | ||
| 14 | + position: relative; | ||
| 15 | + top: 13px; | ||
| 16 | + font-family: 'Open Sans Light',X-LocaleSpecific-Light,'Open Sans',X-LocaleSpecific,sans-serif; | ||
| 17 | + font-weight: normal; | ||
| 18 | + line-height: 100%; | ||
| 19 | + text-shadow: 0 1px 0 rgba(255,255,255,0.75); | ||
| 20 | + color: #484848; | ||
| 21 | + font-size: 30px; | ||
| 22 | + } | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +.main-container { | ||
| 26 | + width: 100%; | ||
| 27 | + display: table; | ||
| 28 | + | ||
| 29 | + .table-wl { | ||
| 30 | + width: 70%; | ||
| 31 | + margin: 0 auto; | ||
| 32 | + margin-top: 40px; | ||
| 33 | + | ||
| 34 | + tbody { | ||
| 35 | + tr { | ||
| 36 | + ._success { | ||
| 37 | + color: #85D42A; | ||
| 38 | + font-weight: bold; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + ._error { | ||
| 42 | + color: red; | ||
| 43 | + font-weight: bold; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + ._processing { | ||
| 47 | + color: #c2c2c2; | ||
| 48 | + font-weight: bold; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | +} | ||
| 0 | \ No newline at end of file | 54 | \ No newline at end of file |
| @@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
| 1 | +var Main = function() { | ||
| 2 | + | ||
| 3 | + function _init() { | ||
| 4 | + | ||
| 5 | + } | ||
| 6 | + | ||
| 7 | + function _getSigns() { | ||
| 8 | + $.ajax({ | ||
| 9 | + type:'GET', | ||
| 10 | + url: '/api/signs', | ||
| 11 | + dataType: 'json' | ||
| 12 | + }).done(function(data) { | ||
| 13 | + _setTable(data); | ||
| 14 | + }).fail(function(err) { | ||
| 15 | + var table = $('.table-wl > tbody'); | ||
| 16 | + | ||
| 17 | + var row = | ||
| 18 | + '<tr>\ | ||
| 19 | + <td>#</td>\ | ||
| 20 | + <td>Ajax Error</td>\ | ||
| 21 | + <td>Ajax Error</td>\ | ||
| 22 | + <td>Ajax Error</td>\ | ||
| 23 | + <td>Ajax Error</td>\ | ||
| 24 | + <td>Ajax Error</td>\ | ||
| 25 | + <tr>'; | ||
| 26 | + | ||
| 27 | + table.append(row); | ||
| 28 | + }); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + function _setTable(data) { | ||
| 32 | + var table = $('.table-wl > tbody'); | ||
| 33 | + | ||
| 34 | + for (var i = 0; i < data.length; i++) { | ||
| 35 | + var row = | ||
| 36 | + '<tr>\ | ||
| 37 | + <td>'+ (i+1) +'</td>\ | ||
| 38 | + <td>'+ data[i].name +'</td>\ | ||
| 39 | + <td>'+ data[i].uuid +'</td>\ | ||
| 40 | + <td>'+ data[i].created_at +'</td>\ | ||
| 41 | + <td>'+ data[i].updated_at +'</td>\ | ||
| 42 | + <td>'+ data[i].status +'</td>\ | ||
| 43 | + </tr>'; | ||
| 44 | + | ||
| 45 | + table.append(row); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + _changeColorStatus(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + function _changeColorStatus() { | ||
| 52 | + var length = $('.table-wl > tbody > tr').length; | ||
| 53 | + var array = $('.table-wl > tbody > tr > td:last-of-type'); | ||
| 54 | + | ||
| 55 | + for (var i = 0; i < length; i++) { | ||
| 56 | + switch($(array[i]).text()) { | ||
| 57 | + case 'Sucesso': | ||
| 58 | + $(array[i]).addClass('_success'); | ||
| 59 | + break; | ||
| 60 | + | ||
| 61 | + case 'Falhou': | ||
| 62 | + $(array[i]).addClass('_error'); | ||
| 63 | + break; | ||
| 64 | + | ||
| 65 | + case 'Processando': | ||
| 66 | + $(array[i]).addClass('_processing'); | ||
| 67 | + break; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return { | ||
| 73 | + run: function() { | ||
| 74 | + _init(); | ||
| 75 | + _getSigns(); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | +}; | ||
| 79 | + | ||
| 80 | +var main = new Main(); | ||
| 81 | +main.run(); | ||
| 0 | \ No newline at end of file | 82 | \ No newline at end of file |
server.js
| @@ -9,13 +9,23 @@ var path = require('path'); | @@ -9,13 +9,23 @@ var path = require('path'); | ||
| 9 | var express = require('express'); | 9 | var express = require('express'); |
| 10 | var app = express(); | 10 | var app = express(); |
| 11 | 11 | ||
| 12 | -app.use(express.static(path.join(__dirname, '/videos'))); | 12 | +/* Database */ |
| 13 | +var mongoose = require('mongoose'); | ||
| 14 | +require('./db/config').connect(mongoose); | ||
| 15 | +var Sign = require('./db/schemas/sinal').init(mongoose); | ||
| 16 | +var API = require('./db/api'); | ||
| 17 | + | ||
| 18 | +app.use(express.static(path.join(__dirname, '/public'))); | ||
| 13 | app.use(express.bodyParser({ keepExtensions: true })); | 19 | app.use(express.bodyParser({ keepExtensions: true })); |
| 14 | 20 | ||
| 15 | app.get('/', function(req, res) { | 21 | app.get('/', function(req, res) { |
| 16 | res.send(200, { 'status': 'server is running!' }); | 22 | res.send(200, { 'status': 'server is running!' }); |
| 17 | }); | 23 | }); |
| 18 | 24 | ||
| 25 | +app.get('/signs', function(req, res) { | ||
| 26 | + res.sendfile('views/index.html'); | ||
| 27 | +}); | ||
| 28 | + | ||
| 19 | app.post('/api', function(req, res) { | 29 | app.post('/api', function(req, res) { |
| 20 | /* Verifica se o paramêtro [servico] existe ou possui algum valor */ | 30 | /* Verifica se o paramêtro [servico] existe ou possui algum valor */ |
| 21 | if ((req.body.servico === '') || (req.body.servico === undefined)) { | 31 | if ((req.body.servico === '') || (req.body.servico === undefined)) { |
| @@ -26,11 +36,35 @@ app.post('/api', function(req, res) { | @@ -26,11 +36,35 @@ app.post('/api', function(req, res) { | ||
| 26 | /* Analisa o tipo de serviço requisitado */ | 36 | /* Analisa o tipo de serviço requisitado */ |
| 27 | switch(req.body.servico) { | 37 | switch(req.body.servico) { |
| 28 | case 'sinal': | 38 | case 'sinal': |
| 29 | - endpoint_sinal.init(req, res); | 39 | + endpoint_sinal.init(req, res, Sign); |
| 40 | + break; | ||
| 41 | + | ||
| 42 | + default: | ||
| 43 | + res.send(500, { 'error': 'Tipo do serviço inválido.'}); | ||
| 30 | break; | 44 | break; |
| 31 | } | 45 | } |
| 32 | }); | 46 | }); |
| 33 | 47 | ||
| 48 | +app.get('/api/signs', function(req, res) { | ||
| 49 | + API.read_all(Sign, function(result) { | ||
| 50 | + if (result !== null) { | ||
| 51 | + res.send(200, result); | ||
| 52 | + } else { | ||
| 53 | + res.send(500, { 'error': 'Erro na busca.'}); | ||
| 54 | + } | ||
| 55 | + }); | ||
| 56 | +}); | ||
| 57 | + | ||
| 58 | +app.delete('/api/:hash', function(req, res) { | ||
| 59 | + API.remove(Sign, req.params.hash, function(result) { | ||
| 60 | + if (result !== null) { | ||
| 61 | + res.send(200, { 'status': 'Remoção concluída.'}); | ||
| 62 | + } else { | ||
| 63 | + res.send(500, { 'error': 'Erro na remoção.'}); | ||
| 64 | + } | ||
| 65 | + }); | ||
| 66 | +}); | ||
| 67 | + | ||
| 34 | app.listen(properties.PORT, properties.HOST, function() { | 68 | app.listen(properties.PORT, properties.HOST, function() { |
| 35 | console.log('Server running on ' + properties.HOST + ':' + properties.PORT); | 69 | console.log('Server running on ' + properties.HOST + ':' + properties.PORT); |
| 36 | }); | 70 | }); |
| 37 | \ No newline at end of file | 71 | \ No newline at end of file |
videos/.gitempty
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +<!DOCTYPE html> | ||
| 2 | +<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | ||
| 3 | +<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | ||
| 4 | +<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | ||
| 5 | +<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> | ||
| 6 | + <head> | ||
| 7 | + <meta charset="utf-8"> | ||
| 8 | + <title>Wikilibras API UI</title> | ||
| 9 | + <meta name="description" content=""> | ||
| 10 | + | ||
| 11 | + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | ||
| 12 | + <link rel="stylesheet" href="assets/css/main.css"> | ||
| 13 | + </head> | ||
| 14 | + <body> | ||
| 15 | + <!--[if lt IE 7]> | ||
| 16 | + <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | ||
| 17 | + <![endif]--> | ||
| 18 | + | ||
| 19 | + <header> | ||
| 20 | + <p>Wikilibras API Interface</p> | ||
| 21 | + </header> | ||
| 22 | + | ||
| 23 | + <section class="main-container"> | ||
| 24 | + <table class="table table-hover table-wl"> | ||
| 25 | + <thead> | ||
| 26 | + <tr> | ||
| 27 | + <th>#</th> | ||
| 28 | + <th>Nome</th> | ||
| 29 | + <th>Hash</th> | ||
| 30 | + <th>Criado em</th> | ||
| 31 | + <th>Atualizado em</th> | ||
| 32 | + <th>Status</th> | ||
| 33 | + </tr> | ||
| 34 | + </thead> | ||
| 35 | + <tbody> | ||
| 36 | + </tbody> | ||
| 37 | + </table> | ||
| 38 | + </section> | ||
| 39 | + | ||
| 40 | + <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | ||
| 41 | + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | ||
| 42 | + <script src="assets/js/main.js"></script> | ||
| 43 | + </body> | ||
| 44 | +</html> | ||
| 0 | \ No newline at end of file | 45 | \ No newline at end of file |