Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김태민
/
OpenSource_Project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
seungmi
2019-12-02 13:05:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1777a0f72e5e5924db350bc3a8df477d962eceba
1777a0f7
1 parent
24f3371f
버그 수정
분류작업이 temp.json파일생성보다 먼저 시행되도록 수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
31 deletions
app.js
app.js
View file @
1777a0f
...
...
@@ -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
...
...
Please
register
or
login
to post a comment