Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.DS_Store

# configuration files
server/config/config.js
config.js

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignores ALL config files


# node
node_modules
6 changes: 4 additions & 2 deletions server/config/express.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var path = require('path'),
express = require('express'),
var express = require('express'),
mongoose = require('mongoose'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
Expand All @@ -14,6 +13,9 @@ module.exports.init = function() {
//initialize app
var app = express();

// Readable JSON output
app.set('json spaces', 4);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better JSON output. Although not necessarily need, better for general debugging JSON


//enable request logging for development debugging
app.use(morgan('dev'));

Expand Down
15 changes: 14 additions & 1 deletion server/controllers/coordinates.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ module.exports = function(req, res, next) {
}

var data = JSON.parse(body);
req.results = data.results[0].geometry.location;
if (data.results.length > 0) {
var coordinates = data.results[0].geometry.location;
req.results = { latitude: coordinates.lat, longitude: coordinates.lng};
} else if (data.status == 'REQUEST_DENIED') {
var debug_message = [
"You need a Google Geocoding API key for this Assignment",
"Get a key at: https://developers.google.com/maps/documentation/geocoding/get-api-key",
"You'd also need a Google Cloud Platform project, with the 'Google Geocoding API' enabled"
];
console.log(debug_message.join("\n"));
} else {
req.results = undefined
console.log(data);
}

@Marcial1234 Marcial1234 Sep 10, 2017

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is the main reason for this PR (see whole file diff)

next();
});
} else {
Expand Down
13 changes: 5 additions & 8 deletions server/controllers/listings.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ exports.create = function(req, res) {
var listing = new Listing(req.body);

/* save the coordinates (located in req.results if there is an address property) */
if(req.results) {
listing.coordinates = {
latitude: req.results.lat,
longitude: req.results.lng
};
if (req.results) {
listing.coordinates = req.results;
}

/* Then save the listing */
Expand All @@ -47,16 +44,16 @@ exports.read = function(req, res) {
exports.update = function(req, res) {
var listing = req.listing;

/* Replace the article's properties with the new properties found in req.body */
/* Replace the listing's properties with the new properties found in req.body */
/* save the coordinates (located in req.results if there is an address property) */
/* Save the article */
/* Save the listing */
};

/* Delete a listing */
exports.delete = function(req, res) {
var listing = req.listing;

/* Remove the article */
/* Remove the listing */
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of typos on this file

/* Retreive all the directory listings, sorted alphabetically by listing code */
Expand Down