Skip to content

Commit

Permalink
GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhyang committed Feb 2, 2020
1 parent cdae0ac commit 6c0ae83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
36 changes: 10 additions & 26 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const Listing = require('./models/listing')
const axios = require('axios')
const req = require('request');


app.use(express.static('build'))
Expand Down Expand Up @@ -44,33 +42,19 @@ app.delete('/api/listings/:id', (req, res, next) => {
})


setTimeout(app.post('/api/listings', (request, response) => {
app.post('/api/listings', (request, response) => {
const body = request.body

const key = process.env.REACT_APP_GEOCODE_KEY
const address = body.window.address.split("+") + ",+Montreal,+QC"
req(`https://maps.googleapis.com/maps/api/geocode/json?address=${address}}&key=${key}`, { json: true }, (err, res, coords) => {
if (err) { return console.log(err); }

const nlat = toString(coords["geometry"].location.lat)
const nlng = toString(coords["geometry"].location.lng)
const listing = new Listing({
posn: { lat:nlat,
lng: nlng,
},
window: body.window,
posting: body.posting,
})

listing.save().then(savedListing => {
response.json(savedListing.toJSON())
})
console.log(coords.url);
console.log(coords.explanation);
});
const listing = new Listing({
posn: body.posn,
window: body.window,
posting: body.posting,
})


}), 10000);
listing.save().then(savedListing => {
response.json(savedListing.toJSON())
})
})

const PORT = 3001
app.listen(PORT, () => {
Expand Down
27 changes: 26 additions & 1 deletion mclet/src/subletForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import React from 'react';

const getCoords = async (addy) => {
const key = process.env.REACT_APP_GEOCODE_KEY
const address = addy.split("+") + ",+Montreal,+QC"
try{
const response = await fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${address}}&key=${key}`);
if(response.ok){
const coords = await response.json();
const nlat = toString(coords["geometry"].location.lat)
const nlng = toString(coords["geometry"].location.lng)
//const parsedData = JSON.parse(jsonResponse);


return {
lat : nlat,
lng : nlng
};

}
throw new Error("Request failed!");
}
catch(error){
console.log(error);
}
}
const sendData = async (data) => {
console.log(data);
try {
Expand Down Expand Up @@ -46,7 +69,9 @@ export class SubletForm extends React.Component{
}

handleClick(){

let newObject = {
posn: getCoords(this.state.addy),
window: {
address: this.state.addy,
nRooms: this.state.nRooms
Expand Down

0 comments on commit 6c0ae83

Please sign in to comment.