Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:nRike/GDG-Hackup-AndroidTitlan

  • Loading branch information...
commit ac0277c85c0ace50da3c10256bb83cf22781e9aa 2 parents ab8705b + cec2792
Fabian Heredia Montiel fabianhjr authored
41 server/app.js
View
@@ -1,6 +1,8 @@
var fs = require("fs");
var express = require("express");
var app = express();
+var backend = require('./backend');
+
app.use(express.bodyParser({ keepExtensions: true, uploadDir: 'uploads/' }));
app.engine('jade', require('jade').__express);
@@ -24,22 +26,29 @@ app.get('/view/:id', function(req, res){
// POST Datos
app.post('/newreport', function(req, res){
- try {
- var report = {
- image: req.files.image,
- location: req.body.location,
- time: req.body.time,
- type: req.body.type
- };
- var reportid = saveReport(report);
- res.status(200);
- res.json({id: reportid});
-
- } catch (err) {
- console.log(err);
- res.status(500);
- res.json(req.params);
- }
+ var image = req.files.image;
+ var report = {
+ image: {
+ path: image.path
+ },
+ location: [
+ req.body.latitude * 1.0,
+ req.body.longitude * 1.0
+ ],
+ time: req.body.time,
+ type: req.body.type
+ };
+ backend.saveReport(report, function(err, report){
+ if(err){
+ console.log(err);
+ res.status(500);
+ res.json(req.params);
+ } else {
+ console.log(report);
+ res.status(200);
+ res.json({id: report.id.toString()});
+ }
+ })
});
app.listen(8080);
41 server/backend.js
View
@@ -0,0 +1,41 @@
+
+var mongoose = require('mongoose');
+var mongo = require('mongo');
+
+var dbUrl = "mongodb://gdg_reporte:gdg_reporte0@ds045507.mongolab.com:45507/gdg_reporte"
+
+var db = mongoose.connect(dbUrl, function(err) {
+ if (err) {
+ console.log("error in mongo connection");
+ throw err;
+ }
+ console.log("connected to mongo");
+});
+
+var Schema = mongoose.Schema;
+
+var Reporte = new Schema({
+ time: Number,
+ type: String,
+ image: {
+ path: String,
+ size: Number
+ },
+ location: [Number]
+});
+Reporte.index({ location: '2d' })
+
+var ReporteModel = db.model('Reporte', Reporte);
+
+var saveReport = function(report, cb){
+ var reporte = new ReporteModel(report)
+ reporte.save(cb);
+};
+
+exports.Reporte = ReporteModel;
+exports.db = db;
+exports.saveReport = saveReport;
+
+
+
+
4 server/package.json
View
@@ -5,7 +5,9 @@
"private": true,
"dependencies": {
"express": "3.x",
- "jade": "*"
+ "jade": "*",
+ "mongoose": "*",
+ "mongo": "*"
},
"engines": {
"node": "0.8.x",
3  server/views/index.jade
View
@@ -3,7 +3,8 @@ html
h1 Hello
form(method='post', action='/newreport', enctype="multipart/form-data")
input(name='image', type='file')
- input(name='location', type='hidden')
+ input(name='latitude', type='hidden', value='0.1')
+ input(name='longitude', type='hidden', value='0.2')
input(name='time', type='hidden')
input(name='type', type='hidden')
input(type='submit') Subir
Please sign in to comment.
Something went wrong with that request. Please try again.