Yuseunggeun

추천 페이지

......@@ -100,6 +100,7 @@ router.get('/rank',function(req,res){
});
});
/*
router.post('/search',function(req,res,next){
console.log('Money : ' + req.body.money);
console.log(req.body);
......@@ -124,8 +125,68 @@ router.post('/search',function(req,res,next){
searchlist : Searchlist,
count : Searchcount
});
});*/
router.post('/search',function(req,res,next){
var fdata = fs.readFileSync('GraphicCard-Price.json'); //파일읽어오기
var datastr = fdata.toString();
var pricejson = JSON.parse(datastr);
var fdata2 = fs.readFileSync('GraphicCard-Benchmark.json'); //파일읽어오기
var datastr2 = fdata2.toString();
var benchmarkjson = JSON.parse(datastr2);
console.log('Money : ' + req.body.money);
console.log(req.body);
var Money = req.body.money; //입력한 예산
var pricelist = new Object();
var benchmarklist = new Object();
var itemlist = new Array();
var Searchcount = 0;
//console.log(pricejson);
for(var key in pricejson){
var price = Number(pricejson[key]['lprice']);
if(price <= Money){
//console.log(price);
var tempitem = new Object();
tempitem = pricejson[key];
tempitem["benchmark"] = benchmarkjson[key]["benchmark"];
tempitem['name'] = benchmarkjson[key]['name'];
//console.log(tempitem);
itemlist.push(tempitem);
//pricelist[key] = pricejson[key];
Searchcount++;
}
}
setTimeout(function(){
console.log(itemlist);
res.render('result',{
money: Money,
itemlist: itemlist,
itemcount: Searchcount
});
}, 1000);
});
/*
function searching(name){
var api_url = 'https://openapi.naver.com/v1/search/shop?query=' + encodeURI(name); // json 결과
......@@ -173,11 +234,8 @@ async function createDB(){
});
};
createDB();
router.post('/shop', function(req, res) {
var keyword = req.body.word;
req.query.query = keyword;
......@@ -201,5 +259,5 @@ router.post('/shop', function(req, res) {
}
});
});
*/
module.exports = router;
\ No newline at end of file
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Cute+Font&display=swap" rel="stylesheet">
<style>
body{
background-color: rgb(192, 233, 192);
color:black;
margin: 0;
padding: 0;
}
h1{
text-align: center;
color: red;
}
img{
height:200px;
}
#item1{
color:white;
}
#item2{
}
#item3{
}
</style>
</head>
<body>
<h1>
추천 결과
</h1>
<script>
</script>
<h2>
<div id = "item1">
<%= itemlist[0]['name'] %>
<br>
<img src = <%= itemlist[0]['image'] %>>
<br>
성능 : <%= itemlist[0]['benchmark'] %>
<br>
가격 : <%= itemlist[0]['lprice'] %>원
<br>
<a href = <%=itemlist[0]['link']%> target=_blank>구매링크</a>
</div>
</h2>
</body>
</html>
\ No newline at end of file