Skip to content

Commit b017674

Browse files
Merge branch 'master' into searchfix
2 parents f853aa4 + 8a5367b commit b017674

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# week6-facn-hosers
22
App to list food and coffee locations around Nazareth
33

4+
Check it out hosted on [heroku](https://facn-app.herokuapp.com/)
5+
46
## User Stories
57
As a tourist in Nazareth looking for somewhere to eat or drink
68
> I want to visit the site and see a list of places with locations, ratings, prices, and descriptions

src/DBquery.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
const dbConnection = require('../database/db_connection.js');
1+
const dbConnection = require('../database/db_connection.js')
22

3-
function getData(search, cb){
4-
if (!search){
5-
dbConnection.query('SELECT shop_name, shop_rating, cost, address, description, tags FROM shops;', (err, res) => {
6-
if (err) cb(err);
7-
cb(null, res.rows);
8-
});
9-
}
10-
else {
11-
// dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags LIKE '%`+ search +`%';`, (err, res)
123

13-
dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags ILIKE '%${search}%';`,
14-
(err, res) => {
15-
if (err) cb(err);
16-
cb(null, res.rows);
17-
});
18-
};
4+
function getAllData(cb){
5+
dbConnection.query('SELECT shop_name, shop_rating, cost, address, description, tags FROM shops;', (err, res) => {
6+
if (err) return cb(err);
7+
cb(null, res.rows);
8+
});
199
}
2010

21-
// function render(err, res){
22-
// if (err) {
23-
// console.log(err);
24-
// return;
25-
// }
26-
// else {
27-
// console.log(res);
28-
// }
29-
// }
30-
// getData(render);
31-
// getData(render, 'coffee');
11+
function getSearchData(search, cb){
12+
dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags ILIKE '%${search}%';`,
13+
(err, res) => {
14+
if (err) return cb(err);
15+
cb(null, res.rows);
16+
});
17+
}
3218

3319
module.exports = {
34-
getData: getData
20+
getAllData: getAllData,
21+
getSearchData: getSearchData
3522
}

src/handler.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
33
const DBquery = require('./DBquery');
4-
const url = require('url');
54

65
const extensionType = {
76
'js': 'application/javascript',
@@ -39,7 +38,7 @@ const assetsHandler = (req, res) => {
3938
}
4039

4140
const allDataHandler = (req, res) => {
42-
DBquery.getData(null,(err, result) => {
41+
DBquery.getAllData((err, result) => {
4342
if (err) throw err;
4443
let table = JSON.stringify(result);
4544
res.writeHead(200, {"content-type": 'application/json'});
@@ -50,7 +49,7 @@ const allDataHandler = (req, res) => {
5049
const searchHandler = (req, res) => {
5150
let searchUrl = req.url;
5251
let searchString = searchUrl.split('?')[1];
53-
DBquery.getData(searchString,(err, result) => {
52+
DBquery.getSearchData(searchString,(err, result) => {
5453
if (err) throw err;
5554
let table = JSON.stringify(result);
5655
res.writeHead(200, {"content-type": 'application/json'});

0 commit comments

Comments
 (0)