chrisheo

feat: Add checkbox with tft search router

...@@ -2,7 +2,7 @@ const express = require('express'); ...@@ -2,7 +2,7 @@ const express = require('express');
2 const router = express.Router(); 2 const router = express.Router();
3 const request = require("request"); 3 const request = require("request");
4 const urlenconde = require('urlencode'); 4 const urlenconde = require('urlencode');
5 -const apikey = "RGAPI-816bb9a0-615c-41e0-a01e-f5e0bb68c3a6"//api 5 +const apikey = "RGAPI-3f849a35-01f8-4915-a606-87cfc4800ef2"//api
6 router.get('/search/summoner/:username/', function (req, res) { 6 router.get('/search/summoner/:username/', function (req, res) {
7 //롤 api url 7 //롤 api url
8 const name = req.params.username; 8 const name = req.params.username;
......
...@@ -2,13 +2,14 @@ module.exports = function (app) { ...@@ -2,13 +2,14 @@ module.exports = function (app) {
2 2
3 var request = require("request"); 3 var request = require("request");
4 var urlenconde = require('urlencode'); 4 var urlenconde = require('urlencode');
5 - var apikey = "RGAPI-899abd44-2f7c-4e2d-981e-7cad9e50d1cb"//api 5 + var apikey = "RGAPI-3f849a35-01f8-4915-a606-87cfc4800ef2"//api
6 6
7 app.get('/', function (req, res) { 7 app.get('/', function (req, res) {
8 res.render('main', { title: 'R U TROLL?' }); 8 res.render('main', { title: 'R U TROLL?' });
9 }); 9 });
10 10
11 - app.get('/search/:username/', function (req, res) { 11 +
12 + app.get('tft/search/:username/', function (req, res) {
12 // tft api url 13 // tft api url
13 const summonerName = req.params.username; 14 const summonerName = req.params.username;
14 var nameUrl = `https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/${summonerName}?api_key=${apikey}` 15 var nameUrl = `https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/${summonerName}?api_key=${apikey}`
...@@ -66,4 +67,80 @@ module.exports = function (app) { ...@@ -66,4 +67,80 @@ module.exports = function (app) {
66 }); 67 });
67 }); 68 });
68 }); 69 });
70 +
71 + app.get('/search/:username/', function(req, res){
72 + //롤 api url
73 + name = req.params.username;
74 + var nameUrl = "https://kr.api.riotgames.com/lol/summoner/v3/summoners/by-name/" + urlenconde(name)+"?api_key="+ apikey;
75 + request(nameUrl,function(error,response,body){
76 + var info_summoner_json = JSON.parse(body);
77 + accountId = info_summoner_json["accountId"];
78 + id = info_summoner_json["id"];
79 + summoner = info_summoner_json["name"];
80 + profileIconId = info_summoner_json["profileIconId"];
81 + summonerLevel = info_summoner_json["summonerLevel"];
82 + revisionDate = info_summoner_json["revisionDate"];
83 + var rankedUrl = "https://kr.api.pvp.net/api/lol/kr/v2.5/league/by-summoner/"+ urlenconde(id)+ "?api_key=" + apikey;
84 + var champUrl = "https://kr.api.pvp.net/api/lol/kr/v1.3/stats/by-summoner/" + urlenconde(id) + "/ranked?api_key=" + apikey;
85 + request(champUrl,function(error,response,body){
86 + var info_champ_json = JSON.parse(body);
87 + var champions = info_champ_json["champions"];
88 + var champ_point = new Array();
89 + var champ_id = new Array();
90 + var champ_name = new Array();
91 + var champ_pic = new Array();
92 + var champions_length = Object.keys(champions).length;
93 + for(var i=0; i < champions_length; i++){
94 + champ_point[i] = (champions[i]["stats"]["totalSessionsWon"]/champions[i]["stats"]["totalSessionsPlayed"]*200)
95 + + ((champions[i]["stats"]["totalAssists"]+champions[i]["stats"]["totalChampionKills"])/champions[i]["stats"]["totalDeathsPerSession"]*100)
96 + + (champions[i]["stats"]["totalSessionsPlayed"]*3);
97 + champ_id[i] = champions[i]["id"];
98 + }
99 + var staticUrl = "https://global.api.pvp.net/api/lol/static-data/kr/v1.2/champion/?api_key=" + apikey;
100 + request(staticUrl,function(error,response,body){
101 + var info_static_champ_json = JSON.parse(body);
102 + var champion = info_static_champ_json["data"];
103 + for(var i=0; i < champ_id.length; i++){
104 + for(js in champion){
105 + for(j in champion[js]){
106 + if(champion[js]["id"] == champ_id[i]){
107 + champ_name[i] = champion[js]["key"];
108 + champ_pic[i] = "https://opgg-static.akamaized.net/images/lol/champion/"+champ_name[i]+".png?image=c_scale,w_46";
109 + }
110 + }
111 + }
112 + }
113 + champ_name[champ_name.length] = "total";
114 + var temp_id;
115 + var temp_name;
116 + var temp_point;
117 + var temp_pic;
118 + for(var i=0; i < champ_id.length-1; i++){
119 + for(var j=i+1;j <champ_id.length-1; j++)
120 + if(champ_point[i] > champ_point[j]){
121 + temp_id = champ_id[i];
122 + temp_name = champ_name[i];
123 + temp_point = champ_point[i];
124 + temp_pic = champ_pic[i];
125 + champ_id[i] = champ_id[j]
126 + champ_name[i] = champ_name[j];
127 + champ_point[i] = champ_point[j];
128 + champ_pic[i] = champ_pic[j];
129 + champ_id[j] = temp_id
130 + champ_name[j] = temp_name;
131 + champ_point[j] = temp_point;
132 + champ_pic[j] = temp_pic;
133 + }
134 + }
135 + res.render('index', { title: req.params.username ,
136 + c_id: champ_id,
137 + c_name: champ_name,
138 + c_point: champ_point,
139 + c_pic: champ_pic,
140 + c_summoner: summoner
141 + });
142 + });
143 + });
144 + });
145 + });
69 }; 146 };
......
...@@ -10,19 +10,44 @@ ...@@ -10,19 +10,44 @@
10 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> 10 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
11 <style> @import url("http://fonts.googleapis.com/earlyaccess/nanumgothic.css");</style> 11 <style> @import url("http://fonts.googleapis.com/earlyaccess/nanumgothic.css");</style>
12 <script> 12 <script>
13 - $(document).ready(function(){ 13 + function search() {
14 +
15 + console.log("---------------------")
16 + var tft_check = $("tft_check").val();
17 + console.log(tft_check)
18 +
19 + var name = $("input").val();
20 + if (tft_check == 1) {
21 + location.href = "http://localhost:3000/tft/search/" + name;
22 +
23 + } else {
24 + location.href = "http://localhost:3000/search/" + name;
25 +
26 + }
27 + }
14 28
29 + $(document).ready(function(){
30 +
15 31
16 $("button#searchButton").click(function(){ 32 $("button#searchButton").click(function(){
33 + console.log("---------------------")
34 + var tft_check = $("tft_check").val();
35 + console.log(tft_check)
36 +
17 var name = $("input").val(); 37 var name = $("input").val();
18 - location.href = "http://localhost:3000/search/" + name; 38 + if (tft_check == 1) {
39 + location.href = "http://localhost:3000/tft/search/" + name;
40 +
41 + } else {
42 + location.href = "http://localhost:3000/search/" + name;
43 +
44 + }
45 +
19 }) 46 })
20 }); 47 });
21 </script> 48 </script>
22 </head> 49 </head>
23 <body> 50 <body>
24 -
25 -
26 <div class="imgOpacity"> 51 <div class="imgOpacity">
27 <div class="center"> 52 <div class="center">
28 <img src= "/FindMelogo.png" width = 150, height = 150/> 53 <img src= "/FindMelogo.png" width = 150, height = 150/>
......
...@@ -15,7 +15,21 @@ ...@@ -15,7 +15,21 @@
15 15
16 $("button#searchButton").click(function(){ 16 $("button#searchButton").click(function(){
17 var name = $("input").val(); 17 var name = $("input").val();
18 - location.href = "http://localhost:3000/search/" + name; 18 + const checkbox = document.getElementById('tft_check');
19 +
20 + // 2. checked 속성을 체크합니다.
21 + const is_checked = checkbox.checked;
22 + console.log("-------------------------------")
23 + console.log(is_checked)
24 + if(is_checked==1){
25 + location.href = "http://localhost:3000/tft/search/" + name;
26 +
27 + } else {
28 + location.href = "http://localhost:3000/search/" + name;
29 +
30 + }
31 +
32 +
19 }) 33 })
20 }); 34 });
21 </script> 35 </script>
...@@ -26,7 +40,12 @@ ...@@ -26,7 +40,12 @@
26 <img src= "FindMelogo.png" width = 300, height = 300/> 40 <img src= "FindMelogo.png" width = 300, height = 300/>
27 </div> 41 </div>
28 <div class="center2"> 42 <div class="center2">
29 - <input type="text" class="input_text" placeholder="소환사 이름"> 43 + <div>
44 + <input type="text" class="input_text" placeholder="소환사 이름">
45 + <input type="checkbox" id="tft_check" name="tft_check" checked>
46 + <label for="tft_check">TFT</label>
47 + </div>
48 +
30 <span class="input-group-btn"> 49 <span class="input-group-btn">
31 <button id="searchButton" class="btn btn-primary" type="button" onclick="search(name)">click!</button> 50 <button id="searchButton" class="btn btn-primary" type="button" onclick="search(name)">click!</button>
32 </span> 51 </span>
......