From 89420d7b4ede7af079c74d8c481399cd8d1efaef Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Thu, 7 Nov 2024 16:03:14 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20=EC=A3=BC=EA=B0=80=20?= =?UTF-8?q?=EC=A7=80=EC=88=98=20API=20response=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/dto/stock.index.response.dto.ts | 33 ++++--- .../dto/stock.index.response.element.dto.ts | 16 +++ BE/src/stock/index/stock.index.controller.ts | 97 ++++++++++++------- 3 files changed, 94 insertions(+), 52 deletions(-) create mode 100644 BE/src/stock/index/dto/stock.index.response.element.dto.ts diff --git a/BE/src/stock/index/dto/stock.index.response.dto.ts b/BE/src/stock/index/dto/stock.index.response.dto.ts index 358266a5..7f26af32 100644 --- a/BE/src/stock/index/dto/stock.index.response.dto.ts +++ b/BE/src/stock/index/dto/stock.index.response.dto.ts @@ -1,25 +1,28 @@ import { ApiProperty } from '@nestjs/swagger'; -import { StockIndexListElementDto } from './stock.index.list.element.dto'; -import { StockIndexValueElementDto } from './stock.index.value.element.dto'; +import { StockIndexResponseElementDto } from './stock.index.response.element.dto'; export class StockIndexResponseDto { - constructor( - indexList: StockIndexListElementDto[], - indexValue: StockIndexValueElementDto[], - ) { - this.indexList = indexList; - this.indexValue = indexValue; - } + @ApiProperty({ + description: '코스피 지수', + type: StockIndexResponseElementDto, + }) + KOSPI: StockIndexResponseElementDto; + + @ApiProperty({ + description: '코스닥 지수', + type: StockIndexResponseElementDto, + }) + KOSDAQ: StockIndexResponseElementDto; @ApiProperty({ - description: '주가 지수 차트 정보 (코스피, 코스닥, 코스피200, KSQ150)', - type: [StockIndexListElementDto], + description: '코스피200 지수', + type: StockIndexResponseElementDto, }) - indexList: StockIndexListElementDto[]; + KOSPI200: StockIndexResponseElementDto; @ApiProperty({ - description: '주가 지수 실시간 값 정보 (코스피, 코스닥, 코스피200, KSQ150)', - type: [StockIndexValueElementDto], + description: 'KSQ150 지수', + type: StockIndexResponseElementDto, }) - indexValue: StockIndexValueElementDto[]; + KSQ150: StockIndexResponseElementDto; } diff --git a/BE/src/stock/index/dto/stock.index.response.element.dto.ts b/BE/src/stock/index/dto/stock.index.response.element.dto.ts new file mode 100644 index 00000000..7ce0ef1a --- /dev/null +++ b/BE/src/stock/index/dto/stock.index.response.element.dto.ts @@ -0,0 +1,16 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { StockIndexValueElementDto } from './stock.index.value.element.dto'; +import { StockIndexListElementDto } from './stock.index.list.element.dto'; + +export class StockIndexResponseElementDto { + @ApiProperty({ + description: '코스피: 0001, 코스닥: 1001, 코스피200: 2001, KSQ150: 3003', + }) + code: string; + + @ApiProperty({ description: '실시간 값', type: StockIndexValueElementDto }) + value: StockIndexValueElementDto; + + @ApiProperty({ description: '실시간 차트', type: StockIndexListElementDto }) + chart: StockIndexListElementDto; +} diff --git a/BE/src/stock/index/stock.index.controller.ts b/BE/src/stock/index/stock.index.controller.ts index c3ddce59..949df5a5 100644 --- a/BE/src/stock/index/stock.index.controller.ts +++ b/BE/src/stock/index/stock.index.controller.ts @@ -28,45 +28,68 @@ export class StockIndexController { async getStockIndex() { const accessToken = await this.koreaInvestmentService.getAccessToken(); - const stockLists = await Promise.all([ - this.stockIndexService.getDomesticStockIndexListByCode( - '0001', - accessToken, - ), // 코스피 - this.stockIndexService.getDomesticStockIndexListByCode( - '1001', - accessToken, - ), // 코스닥 - this.stockIndexService.getDomesticStockIndexListByCode( - '2001', - accessToken, - ), // 코스피200 - this.stockIndexService.getDomesticStockIndexListByCode( - '3003', - accessToken, - ), // KSQ150 - ]); + const [kospiChart, kosdaqChart, kospi200Chart, ksq150Chart] = + await Promise.all([ + this.stockIndexService.getDomesticStockIndexListByCode( + '0001', + accessToken, + ), // 코스피 + this.stockIndexService.getDomesticStockIndexListByCode( + '1001', + accessToken, + ), // 코스닥 + this.stockIndexService.getDomesticStockIndexListByCode( + '2001', + accessToken, + ), // 코스피200 + this.stockIndexService.getDomesticStockIndexListByCode( + '3003', + accessToken, + ), // KSQ150 + ]); - const stockValues = await Promise.all([ - this.stockIndexService.getDomesticStockIndexValueByCode( - '0001', - accessToken, - ), // 코스피 - this.stockIndexService.getDomesticStockIndexValueByCode( - '1001', - accessToken, - ), // 코스닥 - this.stockIndexService.getDomesticStockIndexValueByCode( - '2001', - accessToken, - ), // 코스피200 - this.stockIndexService.getDomesticStockIndexValueByCode( - '3003', - accessToken, - ), // KSQ150 - ]); + const [kospiValue, kosdaqValue, kospi200Value, ksq150Value] = + await Promise.all([ + this.stockIndexService.getDomesticStockIndexValueByCode( + '0001', + accessToken, + ), // 코스피 + this.stockIndexService.getDomesticStockIndexValueByCode( + '1001', + accessToken, + ), // 코스닥 + this.stockIndexService.getDomesticStockIndexValueByCode( + '2001', + accessToken, + ), // 코스피200 + this.stockIndexService.getDomesticStockIndexValueByCode( + '3003', + accessToken, + ), // KSQ150 + ]); - return new StockIndexResponseDto(stockLists, stockValues); + const stockIndexResponse = new StockIndexResponseDto(); + stockIndexResponse.KOSPI = { + code: '0001', + value: kospiValue, + chart: kospiChart, + }; + stockIndexResponse.KOSDAQ = { + code: '1001', + value: kosdaqValue, + chart: kosdaqChart, + }; + stockIndexResponse.KOSPI200 = { + code: '2001', + value: kospi200Value, + chart: kospi200Chart, + }; + stockIndexResponse.KSQ150 = { + code: '3003', + value: ksq150Value, + chart: ksq150Chart, + }; + return stockIndexResponse; } @Cron('*/5 9-16 * * 1-5')