seungmi

버그 수정

분류작업이 temp.json파일생성보다 먼저 시행되도록 수정
Showing 1 changed file with 12 additions and 6 deletions
...@@ -39,7 +39,7 @@ app.get(['/food', '/food/:id'], function(req, res) { ...@@ -39,7 +39,7 @@ app.get(['/food', '/food/:id'], function(req, res) {
39 //사용자가 호출한 search page 39 //사용자가 호출한 search page
40 app.post('/food/search', function(req, res) { 40 app.post('/food/search', function(req, res) {
41 var title = req.body.title; 41 var title = req.body.title;
42 - res.render('map.ejs',{ 42 + res.render('map.ejs', {
43 title: 'Search', 43 title: 'Search',
44 searching: title 44 searching: title
45 }); 45 });
...@@ -60,13 +60,18 @@ app.post('/food/recommendation', function(req, res) { ...@@ -60,13 +60,18 @@ app.post('/food/recommendation', function(req, res) {
60 var list = { 60 var list = {
61 food: [] 61 food: []
62 }; 62 };
63 +
64 + function add(users, price, shape, kinds, list, callback) {
63 for (var foods in users) { 65 for (var foods in users) {
64 if ((!price || users[foods]['price'] == price) && (!shape || users[foods]['shape'] == shape) && (!kinds || users[foods]['kinds'] == kinds)) { 66 if ((!price || users[foods]['price'] == price) && (!shape || users[foods]['shape'] == shape) && (!kinds || users[foods]['kinds'] == kinds)) {
65 list.food.push(foods); 67 list.food.push(foods);
66 } 68 }
67 // $('<li>').text(foods).appendTo('#users'); 69 // $('<li>').text(foods).appendTo('#users');
68 } 70 }
71 + callback(list);
72 + }
69 73
74 + add(users, price, shape, kinds, list, function(list) {
70 fs.writeFile('data/temp.json', JSON.stringify(list), "utf8", function(err) { 75 fs.writeFile('data/temp.json', JSON.stringify(list), "utf8", function(err) {
71 if (err) { 76 if (err) {
72 console.log(err); 77 console.log(err);
...@@ -87,15 +92,16 @@ app.post('/food/recommendation', function(req, res) { ...@@ -87,15 +92,16 @@ app.post('/food/recommendation', function(req, res) {
87 title: 'Recommendation', 92 title: 'Recommendation',
88 description: 'We recommend this...', 93 description: 'We recommend this...',
89 randvalue: food_value 94 randvalue: food_value
90 - });//rander closed 95 + }); //rander closed
91 } 96 }
92 - });//readFile closed 97 + }); //readFile closed
93 } 98 }
94 - });//writeFile closed 99 + }); //writeFile closed
100 + });//add closed
95 101
96 } 102 }
97 - });//readFile closed 103 + }); //readFile closed
98 -});//post closed 104 +}); //post closed
99 105
100 106
101 107
......