Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
833a243
#75 build(be): JPA dependencies 추가
ki-met-hoon Jan 28, 2025
47d61ba
build(be): gitiginore env 파일 추가
ki-met-hoon Jan 28, 2025
5178f47
style(be): MinutePriceResponse -> MinutePriceDetailedResponse
ki-met-hoon Jan 28, 2025
7c639e1
#75 build(be): yml 파일 내 mongodb 환경 설정
ki-met-hoon Jan 28, 2025
febd745
style(be): Schedule 장 시작 시간 변경
ki-met-hoon Jan 28, 2025
bc38980
#75 feat(be): MinutePrice Document 생성
ki-met-hoon Jan 28, 2025
78c4691
#75 feat(be): MinutePriceRepository 구현
ki-met-hoon Jan 28, 2025
19babf5
#76 feat(be): toEntity method 구현
ki-met-hoon Jan 28, 2025
f63e971
#76 feat(be): registerMinutePriceSchedulers method 구현
ki-met-hoon Jan 28, 2025
12baec9
#76 feat(be): createMinutePriceTask method 구현
ki-met-hoon Jan 28, 2025
42696a6
#77 feat(be): CODE_TO_NAME_MAP method 구현
ki-met-hoon Jan 28, 2025
d6abe0d
#77 feat(be): CandlePriceHistoryResponse DTO 구현
ki-met-hoon Jan 28, 2025
1f15799
#77 feat(be): MinutePriceRepository 내 findAllByCode method 구현
ki-met-hoon Jan 28, 2025
318ab08
#77 feat(be): getCandlePriceHistoryByCode method 구현
ki-met-hoon Jan 28, 2025
447de52
#76 feat(be): MongoConfig class 생성, mappingMongoConverter 구현
ki-met-hoon Jan 28, 2025
6ccca82
#77 feat(be): handleCandlePriceHistory method 구현
ki-met-hoon Jan 28, 2025
e0d56f9
#77 refactor(be): objectMapper 삭제, @JsonNaming 추가
ki-met-hoon Jan 28, 2025
f776421
#77 feat(be): code field index 추가
ki-met-hoon Jan 28, 2025
6668a06
#75 build(be): DB 정보 env 변수 처리
ki-met-hoon Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/stock_server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ $RECYCLE.BIN/
*.lnk

# env file
dev.env
*.env

# End of https://www.toptal.com/developers/gitignore/api/windows,macos,intellij,visualstudiocode,java,linux
1 change: 1 addition & 0 deletions src/backend/stock_server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ext {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jootalkpia.stock_server.stocks.advice;

import com.jootalkpia.stock_server.stocks.dto.request.TokenRequestBody;
import com.jootalkpia.stock_server.stocks.dto.response.MinutePriceResponse;
import com.jootalkpia.stock_server.stocks.dto.response.MinutePriceDetailedResponse;
import com.jootalkpia.stock_server.stocks.dto.response.TokenResponse;
import com.jootalkpia.stock_server.support.config.FeignConfig;
import org.springframework.cloud.openfeign.FeignClient;
Expand All @@ -13,14 +13,14 @@ public interface StockCaller {
TokenResponse getToken(@RequestBody TokenRequestBody tokenRequestBody);

@GetMapping(name = "MinutePriceAPI", value = "${feign.minute-price.path}")
MinutePriceResponse getMinutePrice(@RequestHeader(name = "authorization") String token,
@RequestHeader(name = "appkey") String appKey,
@RequestHeader(name = "appsecret") String appSecret,
@RequestHeader(name = "tr_id") String trId,
@RequestHeader(name = "custtype") String custType,
@RequestParam("FID_ETC_CLS_CODE") String etcClsCode,
@RequestParam("FID_COND_MRKT_DIV_CODE") String marketDivCode,
@RequestParam("FID_INPUT_ISCD") String itemCode,
@RequestParam("FID_INPUT_HOUR_1") String inputHour,
@RequestParam("FID_PW_DATA_INCU_YN") String pwDataIncuYn);
MinutePriceDetailedResponse getMinutePrice(@RequestHeader(name = "authorization") String token,
@RequestHeader(name = "appkey") String appKey,
@RequestHeader(name = "appsecret") String appSecret,
@RequestHeader(name = "tr_id") String trId,
@RequestHeader(name = "custtype") String custType,
@RequestParam("FID_ETC_CLS_CODE") String etcClsCode,
@RequestParam("FID_COND_MRKT_DIV_CODE") String marketDivCode,
@RequestParam("FID_INPUT_ISCD") String itemCode,
@RequestParam("FID_INPUT_HOUR_1") String inputHour,
@RequestParam("FID_PW_DATA_INCU_YN") String pwDataIncuYn);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.jootalkpia.stock_server.stocks.controller;

import com.jootalkpia.stock_server.stocks.dto.response.MinutePriceSimpleResponse;
import com.jootalkpia.stock_server.stocks.dto.response.CandlePriceHistoryResponse;
import com.jootalkpia.stock_server.stocks.service.StockService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
@RestController
public class StockController {
private final StockService stockService;

@GetMapping("")
public ResponseEntity<String> handleMinutePrice() {
return ResponseEntity.ok("hi");
@GetMapping("/api/v1/stock/candlesticks/{stock_code}")
public ResponseEntity<CandlePriceHistoryResponse> handleCandlePriceHistory(@PathVariable("stock_code") String code, @PageableDefault(size = 180) Pageable pageable) {
return ResponseEntity.ok(stockService.getCandlePriceHistoryByCode(pageable, code));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jootalkpia.stock_server.stocks.domain;

public enum Schedule {
MORNING("0 33-59 23 * * MON-FRI"),
MORNING("0 1-59 9 * * MON-FRI"),
TRADING_HOURS("0 * 10-14 * * MON-FRI"),
CLOSING("0 0-31 16 * * MON-FRI"),
MIDNIGHT("0 0 0 * * MON-FRI");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package com.jootalkpia.stock_server.stocks.domain;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum StockCode {
SAMSUNG_ELECTRONICS("005930"),
KAKAO("035720"),
SK_HYNIX("000660"),
NAVER("035420"),
HANWHA_AEROSPACE("012450");
SAMSUNG_ELECTRONICS("005930", "삼성전자"),
KAKAO("035720", "카카오"),
SK_HYNIX("000660", "SK하이닉스"),
NAVER("035420", "네이버"),
HANWHA_AEROSPACE("012450", "한화에어로스페이스");

private final String code;
private final String name;

private static final Map<String, String> CODE_TO_NAME_MAP = Arrays.stream(values())
.collect(Collectors.toMap(
StockCode::getCode,
StockCode::getName
));

StockCode(String code) {
StockCode(String code, String name) {
this.code = code;
this.name = name;
}

public String getCode() {
return code;
}

public String getName() {
return name;
}

public static String getNameByCode(String code) {
return CODE_TO_NAME_MAP.get(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.jootalkpia.stock_server.stocks.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Document(collection = "minute_price")
public class MinutePrice {
@Id
private ObjectId minutePriceId;

@Indexed(background = true)
private String code;

@Field("stock_name")
private String stockName;

@Field("business_date")
private String businessDate;

@Field("trading_time")
private String tradingTime;

@Field("current_price")
private String currentPrice;

@Field("open_price")
private String openPrice;

@Field("high_price")
private String highPrice;

@Field("low_price")
private String lowPrice;

@Field("trading_volume")
private String tradingVolume;

@Field("total_trade_amount")
private String totalTradeAmount;

protected MinutePrice() {
}

private MinutePrice(
String code,
String htsKorIsnm,
String stckBsopDate,
String stckCntgHour,
String stckPrpr,
String stckOprc,
String stckHgpr,
String stckLwpr,
String cntgVol,
String acmlTrPbmn) {
this.code = code;
this.stockName = htsKorIsnm;
this.businessDate = stckBsopDate;
this.tradingTime = stckCntgHour;
this.currentPrice = stckPrpr;
this.openPrice = stckOprc;
this.highPrice = stckHgpr;
this.lowPrice = stckLwpr;
this.tradingVolume = cntgVol;
this.totalTradeAmount = acmlTrPbmn;
}

public static MinutePrice of(
String code,
String htsKorIsnm,
String stckBsopDate,
String stckCntgHour,
String stckPrpr,
String stckOprc,
String stckHgpr,
String stckLwpr,
String cntgVol,
String acmlTrPbmn) {
return new MinutePrice(
code,
htsKorIsnm,
stckBsopDate,
stckCntgHour,
stckPrpr,
stckOprc,
stckHgpr,
stckLwpr,
cntgVol,
acmlTrPbmn
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.jootalkpia.stock_server.stocks.dto.response;

import com.jootalkpia.stock_server.stocks.domain.StockCode;
import com.jootalkpia.stock_server.stocks.dto.MinutePrice;
import org.springframework.data.domain.Page;

import java.util.List;

public record CandlePriceHistoryResponse(
String code,
String stockName,
List<Output> output,
long totalCount
) {

public static CandlePriceHistoryResponse of(Page<MinutePrice> minutePricePage, String code) {
return new CandlePriceHistoryResponse(
code,
StockCode.getNameByCode(code),
minutePricePage.getContent().stream()
.map(Output::of)
.toList(),
minutePricePage.getTotalElements()
);
}

public record Output(
String businessDate,
String tradingTime,
String currentPrice,
String openPrice,
String highPrice,
String lowPrice,
String tradingVolume,
String totalTradeAmount
) {

public static Output of(MinutePrice minutePrice) {
return new Output(
minutePrice.getBusinessDate(),
minutePrice.getTradingTime(),
minutePrice.getCurrentPrice(),
minutePrice.getOpenPrice(),
minutePrice.getHighPrice(),
minutePrice.getLowPrice(),
minutePrice.getTradingVolume(),
minutePrice.getTotalTradeAmount()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.jootalkpia.stock_server.stocks.dto.response;

import java.util.ArrayList;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

public record MinutePriceResponse(
import java.util.List;

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record MinutePriceDetailedResponse(
Output1 output1,
ArrayList<Output2> output2,
List<Output2> output2,
String rtCd,
String msgCd,
String msg1
) {
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record Output1(
String prdyVrss,
String prdyVrssSign,
Expand All @@ -20,6 +25,7 @@ public record Output1(
String stckPrpr
) {}

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record Output2(
String stckBsopDate,
String stckCntgHour,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jootalkpia.stock_server.stocks.dto.response;

import com.jootalkpia.stock_server.stocks.dto.MinutePrice;

public record MinutePriceSimpleResponse(
String code,
String htsKorIsnm,
Expand All @@ -13,7 +15,7 @@ public record MinutePriceSimpleResponse(
String acmlTrPbmn
) {

public static MinutePriceSimpleResponse from(MinutePriceResponse minutePriceDto, String code) {
public static MinutePriceSimpleResponse from(MinutePriceDetailedResponse minutePriceDto, String code) {
return new MinutePriceSimpleResponse(
code,
minutePriceDto.output1().htsKorIsnm(),
Expand All @@ -27,4 +29,19 @@ public static MinutePriceSimpleResponse from(MinutePriceResponse minutePriceDto,
minutePriceDto.output2().get(1).acmlTrPbmn()
);
}

public MinutePrice toDocument() {
return MinutePrice.of(
code,
htsKorIsnm,
stckBsopDate,
stckCntgHour,
stckPrpr,
stckOprc,
stckHgpr,
stckLwpr,
cntgVol,
acmlTrPbmn
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jootalkpia.stock_server.stocks.repository;

import com.jootalkpia.stock_server.stocks.dto.MinutePrice;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface MinutePriceRepository extends MongoRepository<MinutePrice, String> {
Page<MinutePrice> findAllByCode(Pageable pageable, String code);
}
Loading
Loading