Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#17-add-efk-log
Browse files Browse the repository at this point in the history
  • Loading branch information
ur2e authored Dec 10, 2022
2 parents 8307b81 + dfc22de commit 6f5068d
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 43 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: backend - CI
on:
push:
branches:
- develop
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: kakaoasset-backend
jobs:
build-and-push-image:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Docker Build and ECR push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}

- name: Move Repository
uses: actions/checkout@master
with:
repository: kakao-asset/k8s
token: ${{ secrets.TOKEN }}
path: .

- name: Edit Back Deploy menifest
run: |
sed -i "20 c\ image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}" back-deploy.yaml
git config --global user.email "[email protected]"
git config --global user.name "ur2e"
git add .
git commit -m "update back-deploy.yaml"
git push -f --set-upstream origin main
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM gradle:7.4-jdk17-alpine as builder
WORKDIR /build
COPY . /build/
RUN chmod 777 gradlew
RUN ./gradlew bootJar
WORKDIR /build/build/libs

FROM eclipse-temurin:11-jre-alpine
COPY --from=builder /build/build/libs/kakaoasset-0.0.1-SNAPSHOT.jar kakaoasset-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "kakaoasset-0.0.1-SNAPSHOT.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ public class NewsStockController {
private NewsStockService newsStockService;

@RequestMapping(value = "/main/news", method = RequestMethod.GET)
public String news(@RequestParam String stockCode) {
String result = "";

result = newsStockService.selectNewsStock(stockCode);

public Object news(@RequestParam String stockCode) {
Object result = newsStockService.selectNewsStock(stockCode);
return result;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class HistoryResponseDto {
private String stockName;
private boolean tradeType;
private String tradeDate;
private String tradeTime;
private int price;
private int quantity;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/kakaoasset/portfolio/entity/Asset.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.kakaoasset.portfolio.entity;

import com.kakaoasset.portfolio.dto.CashDto;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -26,8 +24,11 @@ public Asset(Long id, int cash){
this.cash = cash;
}

public Asset updateCash(int cash){
public void updateCash(int cash){
this.cash = cash;
return this;
}

public void updateBuyPrice(int buyPrice){
this.buyPrice = buyPrice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import java.util.Collection;
import java.util.Collections;

@Service
public class NewsStockService {
public String selectNewsStock(String stockCode) {
public Object selectNewsStock(String stockCode) {
String result = "";
JSONArray jsonarr = new JSONArray();
String detail_url = "https://finance.daum.net/quotes/";

System.out.println("news test");
// make request for elasticsearch api
RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add((request, body, execution) -> {
Expand All @@ -32,11 +35,10 @@ public String selectNewsStock(String stockCode) {
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();
return Collections.emptyList();
}

// 뉴스 크롤링에 대한 response + 상세페이지를 보여주기 위한 newsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class RealtimeStockService {
@Value("${elasticsearch.host}")
private String host;

@Value("${index.multi-stock-index}")
private String multiIndex;

public String selectRealtimeStock(String stock_name){
String index = "stock-data";
JSONArray jsonarr = new JSONArray();
String result = null;

Expand All @@ -35,7 +37,7 @@ public String selectRealtimeStock(String stock_name){
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();
result = restTemplate.exchange("http://"+host+":9200/"+multiIndex+"/_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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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;

@Value("${index.stock-rank-index}")
private String rankIndex;


public String selectSearchRank(){
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/"+rankIndex+"/_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);
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class SectorService {
@Value("${elasticsearch.host}")
private String host;

@Value("${index.multi-stock-index}")
private String multiIndex;

public String selectSectorStock(String stock_sector){
String index = "stock-data";
JSONArray jsonarr = new JSONArray();
String result = null;
String personResultAsJsonStr = null;
Expand Down Expand Up @@ -107,7 +109,7 @@ public String selectSectorStock(String stock_sector){
new HttpEntity<String>(req_json.toString(), headers);

personResultAsJsonStr =
restTemplate.postForObject("http://"+host+":9200/"+index+"/_search", request, String.class);
restTemplate.postForObject("http://"+host+":9200/"+multiIndex+"/_search", request, String.class);

}catch (HttpClientErrorException e){
// no index
Expand All @@ -129,8 +131,6 @@ public String selectSectorStock(String stock_sector){
temp.put("id", ((JSONObject) ((JSONObject) json.getJSONObject("aggregations").getJSONObject("groupby").getJSONArray("buckets").get(i)).getJSONObject("cae43aee").getJSONObject("hits").getJSONArray("hits").get(0)).get("_id"));

jsonarr.put(temp);


}
return jsonarr.toString();
}
Expand Down
Loading

0 comments on commit 6f5068d

Please sign in to comment.