-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor: 폴더 구조 변경
- Loading branch information
Showing
8 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/com/kakaoasset/portfolio/controller/NewsStockController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kakaoasset.portfolio.controller; | ||
|
||
import com.kakaoasset.portfolio.service.NewsStockService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@CrossOrigin(origins = "*") | ||
public class NewsStockController { | ||
|
||
@Autowired | ||
private NewsStockService newsStockService; | ||
|
||
@RequestMapping(value = "/main/news", method = RequestMethod.GET) | ||
public String news(@RequestParam String stockCode) { | ||
String result = ""; | ||
|
||
result = newsStockService.selectNewsStock(stockCode); | ||
|
||
return result; | ||
} | ||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/kakaoasset/portfolio/controller/RealtimeStockController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.kakaoasset.portfolio.controller; | ||
import com.kakaoasset.portfolio.service.RealtimeStockService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@CrossOrigin(origins = "*") | ||
public class RealtimeStockController { | ||
|
||
@Autowired | ||
private RealtimeStockService realtimeStockService; | ||
|
||
@RequestMapping(value = "/main/realtime", method = RequestMethod.GET) | ||
public String realtimeStock(@RequestParam String stock_name){ | ||
|
||
String result = null; | ||
|
||
result = realtimeStockService.selectRealtimeStock(stock_name); | ||
|
||
return result; | ||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
src/main/java/com/kakaoasset/portfolio/controller/SearchRankController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.kakaoasset.portfolio.controller; | ||
|
||
import com.kakaoasset.portfolio.service.SearchRankService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* packageName : com.kakaoasset.portfolio.elasticsearch.elasticAPI.controller | ||
* fileName : SearchRankController | ||
* author : Hwang | ||
* date : 2022-11-14 | ||
*/ | ||
|
||
@RestController | ||
@CrossOrigin(origins = "*") | ||
public class SearchRankController { | ||
|
||
@Autowired | ||
private SearchRankService searchRankService; | ||
|
||
@RequestMapping(value = "/search/rank", method = RequestMethod.GET) | ||
public String searchRank(){ | ||
|
||
String result = null; | ||
|
||
result = searchRankService.selectSearchRank(); | ||
|
||
return result; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/kakaoasset/portfolio/controller/SectorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.kakaoasset.portfolio.controller; | ||
|
||
import com.kakaoasset.portfolio.service.SectorService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* packageName : com.kakaoasset.portfolio.elasticsearch.elasticAPI.controller | ||
* fileName : SectorController | ||
* author : Hwang | ||
* date : 2022-11-14 | ||
*/ | ||
|
||
@RestController | ||
@CrossOrigin(origins = "*") | ||
public class SectorController { | ||
|
||
@Autowired | ||
private SectorService sectorService; | ||
|
||
@RequestMapping(value = "/sector", method = RequestMethod.GET) | ||
public String searchRank(@RequestParam String stock_sector){ | ||
|
||
String result = null; | ||
|
||
result = sectorService.selectSectorStock(stock_sector); | ||
|
||
return result; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/kakaoasset/portfolio/service/NewsStockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.kakaoasset.portfolio.service; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class NewsStockService { | ||
public String selectNewsStock(String stockCode) { | ||
String result = ""; | ||
JSONArray jsonarr = new JSONArray(); | ||
String detail_url = "https://finance.daum.net/quotes/"; | ||
|
||
// make request for elasticsearch api | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.getInterceptors().add((request, body, execution) -> { | ||
ClientHttpResponse response = execution.execute(request,body); | ||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON); | ||
return response; | ||
}); | ||
|
||
final HttpHeaders headers = new HttpHeaders(); | ||
headers.add("Referer","http://finance.daum.net"); | ||
headers.add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 OPR/58.0.3135.127"); | ||
final HttpEntity<?> entity = new HttpEntity<>(headers); | ||
try { | ||
// send request to elasticsearch | ||
|
||
result = restTemplate.exchange("https://finance.daum.net/content/news?page=1&perPage=5&category=economy&searchType=all&keyword=" + stockCode, HttpMethod.GET, entity, String.class).getBody(); | ||
}catch (HttpClientErrorException e){ | ||
// no index | ||
return new JSONObject("{\"error\":\"No Index\", \"index\":\""+stockCode+"\"}").toString(); | ||
} | ||
|
||
// 뉴스 크롤링에 대한 response + 상세페이지를 보여주기 위한 newsId | ||
JSONObject json = new JSONObject(result); | ||
if(JSONObject.NULL != json.get("data")){ | ||
for (int i = 0; i < json.getJSONArray("data").length(); i++) { | ||
JSONObject temp = (JSONObject) json.getJSONArray("data").get(i); | ||
String newsId = ((JSONObject)json.getJSONArray("data").get(i)).getString("newsId"); | ||
temp.put("detail_url", detail_url + stockCode + "#news/stock/" + newsId); | ||
jsonarr.put(temp); | ||
} | ||
} | ||
|
||
return jsonarr.toString(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/kakaoasset/portfolio/service/RealtimeStockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.kakaoasset.portfolio.service; | ||
|
||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class RealtimeStockService { | ||
|
||
@Value("${elasticsearch.host}") | ||
private String host; | ||
|
||
public String selectRealtimeStock(String stock_name){ | ||
String index = "stock-data"; | ||
JSONArray jsonarr = new JSONArray(); | ||
String result = null; | ||
|
||
// make request for elasticsearch api | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.getInterceptors().add((request, body, execution) -> { | ||
ClientHttpResponse response = execution.execute(request,body); | ||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON); | ||
return response; | ||
}); | ||
final HttpHeaders headers = new HttpHeaders(); | ||
final HttpEntity<?> entity = new HttpEntity<>(headers); | ||
try { | ||
// send request to elasticsearch | ||
result = restTemplate.exchange("http://"+host+":9200/"+index+"/_search?sort=datetime:acs&size=10000&q=" + stock_name, HttpMethod.GET, entity, String.class).getBody(); | ||
}catch (HttpClientErrorException e){ | ||
// no index | ||
return new JSONObject("{\"error\":\"No Index\", \"index\":\""+stock_name+"\"}").toString(); | ||
} | ||
|
||
JSONObject json = new JSONObject(result); | ||
for (int i = 0; i < json.getJSONObject("hits").getJSONArray("hits").length(); i++) { | ||
JSONObject temp = ((JSONObject) json.getJSONObject("hits").getJSONArray("hits").get(i)).getJSONObject("_source"); | ||
jsonarr.put(temp); | ||
} | ||
return jsonarr.toString(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/kakaoasset/portfolio/service/SearchRankService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.kakaoasset.portfolio.service; | ||
|
||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
/** | ||
*packageName : com.kakaoasset.portfolio.elasticsearch.elasticAPI.service | ||
* fileName : SearchRankController | ||
* author : Hwang | ||
* date : 2022-11-14 | ||
*/ | ||
|
||
@Service | ||
public class SearchRankService { | ||
|
||
@Value("${elasticsearch.host}") | ||
private String host; | ||
|
||
public String selectSearchRank(){ | ||
|
||
String index = "stock-rank"; | ||
JSONArray jsonarr = new JSONArray(); | ||
String result = null; | ||
|
||
// make request for elasticsearch api | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.getInterceptors().add((request, body, execution) -> { | ||
ClientHttpResponse response = execution.execute(request,body); | ||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON); | ||
return response; | ||
}); | ||
final HttpHeaders headers = new HttpHeaders(); | ||
final HttpEntity<?> entity = new HttpEntity<>(headers); | ||
try { | ||
// send request to elasticsearch | ||
|
||
result = restTemplate.exchange("http://"+host+":9200/"+index+"/_search?sort=datetime:acs", HttpMethod.GET, entity, String.class).getBody(); | ||
}catch (HttpClientErrorException e){ | ||
// no index | ||
return new JSONObject("{\"error\":\"No Index\"").toString(); | ||
} | ||
|
||
JSONObject json = new JSONObject(result); | ||
|
||
System.out.println("-------------------------------api-search-rank---------------------------"); | ||
|
||
for (int i = 0; i < json.getJSONObject("hits").getJSONArray("hits").length(); i++) { | ||
JSONObject temp = ((JSONObject) json.getJSONObject("hits").getJSONArray("hits").get(i)).getJSONObject("_source"); | ||
jsonarr.put(temp); | ||
} | ||
return jsonarr.toString(); | ||
} | ||
} |
Oops, something went wrong.