seungmi

버그 수정

분류작업이 temp.json파일생성보다 먼저 시행되도록 수정
Showing 1 changed file with 37 additions and 31 deletions
......@@ -39,7 +39,7 @@ app.get(['/food', '/food/:id'], function(req, res) {
//사용자가 호출한 search page
app.post('/food/search', function(req, res) {
var title = req.body.title;
res.render('map.ejs',{
res.render('map.ejs', {
title: 'Search',
searching: title
});
......@@ -60,42 +60,48 @@ app.post('/food/recommendation', function(req, res) {
var list = {
food: []
};
for (var foods in users) {
if ((!price || users[foods]['price'] == price) && (!shape || users[foods]['shape'] == shape) && (!kinds || users[foods]['kinds'] == kinds)) {
list.food.push(foods);
function add(users, price, shape, kinds, list, callback) {
for (var foods in users) {
if ((!price || users[foods]['price'] == price) && (!shape || users[foods]['shape'] == shape) && (!kinds || users[foods]['kinds'] == kinds)) {
list.food.push(foods);
}
// $('<li>').text(foods).appendTo('#users');
}
// $('<li>').text(foods).appendTo('#users');
callback(list);
}
fs.writeFile('data/temp.json', JSON.stringify(list), "utf8", function(err) {
if (err) {
console.log(err);
res.status(500).send('Internal Server Error');
} else {
add(users, price, shape, kinds, list, function(list) {
fs.writeFile('data/temp.json', JSON.stringify(list), "utf8", function(err) {
if (err) {
console.log(err);
res.status(500).send('Internal Server Error');
} else {
fs.readFile('data/temp.json', 'utf8', function(err, data) {
if (err) {
console.log((err));
res.status(500).send('Internal Server Error');
} else {
var food = JSON.parse(data)['food'];
var length = food.length;
var rand = Math.floor(Math.random() * length); //(Math.random() * (max - min)) + min
var food_value = food[rand];
console.log(rand);
res.render('print.ejs', {
title: 'Recommendation',
description: 'We recommend this...',
randvalue: food_value
});//rander closed
}
});//readFile closed
}
});//writeFile closed
fs.readFile('data/temp.json', 'utf8', function(err, data) {
if (err) {
console.log((err));
res.status(500).send('Internal Server Error');
} else {
var food = JSON.parse(data)['food'];
var length = food.length;
var rand = Math.floor(Math.random() * length); //(Math.random() * (max - min)) + min
var food_value = food[rand];
console.log(rand);
res.render('print.ejs', {
title: 'Recommendation',
description: 'We recommend this...',
randvalue: food_value
}); //rander closed
}
}); //readFile closed
}
}); //writeFile closed
});//add closed
}
});//readFile closed
});//post closed
}); //readFile closed
}); //post closed
......