From 8c246afb7475320842fb49e363f5b6983993f068 Mon Sep 17 00:00:00 2001 From: JIN Date: Thu, 14 Nov 2024 13:36:18 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A2=85=EB=AA=A9=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=EB=A7=9E=EB=8A=94=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=84=20DB=EC=97=90=EC=84=9C=20=EA=BA=BC=EB=82=B4=EC=99=80?= =?UTF-8?q?=20=EB=B3=B4=EB=82=B4=EC=A3=BC=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/stock/detail/stock-detail.entity.ts | 13 ++++++++ BE/src/stock/detail/stock-detail.module.ts | 7 ++-- .../stock/detail/stock-detail.repository.ts | 15 +++++++++ BE/src/stock/detail/stock-detail.service.ts | 33 ++++++++++++------- 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 BE/src/stock/detail/stock-detail.entity.ts create mode 100644 BE/src/stock/detail/stock-detail.repository.ts diff --git a/BE/src/stock/detail/stock-detail.entity.ts b/BE/src/stock/detail/stock-detail.entity.ts new file mode 100644 index 00000000..37182a41 --- /dev/null +++ b/BE/src/stock/detail/stock-detail.entity.ts @@ -0,0 +1,13 @@ +import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm'; + +@Entity() +export class Stocks extends BaseEntity { + @PrimaryColumn() + code: string; + + @Column() + name: string; + + @Column() + market: string; +} diff --git a/BE/src/stock/detail/stock-detail.module.ts b/BE/src/stock/detail/stock-detail.module.ts index cfb2b57b..b6447a76 100644 --- a/BE/src/stock/detail/stock-detail.module.ts +++ b/BE/src/stock/detail/stock-detail.module.ts @@ -1,11 +1,14 @@ import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; import { KoreaInvestmentModule } from '../../koreaInvestment/korea-investment.module'; import { StockDetailController } from './stock-detail.controller'; import { StockDetailService } from './stock-detail.service'; +import { StockDetailRepository } from './stock-detail.repository'; +import { Stocks } from './stock-detail.entity'; @Module({ - imports: [KoreaInvestmentModule], + imports: [KoreaInvestmentModule, TypeOrmModule.forFeature([Stocks])], controllers: [StockDetailController], - providers: [StockDetailService], + providers: [StockDetailService, StockDetailRepository], }) export class StockDetailModule {} diff --git a/BE/src/stock/detail/stock-detail.repository.ts b/BE/src/stock/detail/stock-detail.repository.ts new file mode 100644 index 00000000..d9143719 --- /dev/null +++ b/BE/src/stock/detail/stock-detail.repository.ts @@ -0,0 +1,15 @@ +import { InjectDataSource } from '@nestjs/typeorm'; +import { Injectable } from '@nestjs/common'; +import { DataSource, Repository } from 'typeorm'; +import { Stocks } from './stock-detail.entity'; + +@Injectable() +export class StockDetailRepository extends Repository { + constructor(@InjectDataSource() dataSource: DataSource) { + super(Stocks, dataSource.createEntityManager()); + } + + async findOneByCode(code: string) { + return this.findOne({ where: { code } }); + } +} diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index 8031c4d6..1c1268bb 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -10,12 +10,16 @@ import { InquirePriceOutputData, } from './interface/stock-detail.interface'; import { InquirePriceResponseDto } from './dto/stock-detail-response.dto'; +import { StockDetailRepository } from './stock-detail.repository'; @Injectable() export class StockDetailService { private readonly logger = new Logger(); - constructor(private readonly koreaInvetmentService: KoreaInvestmentService) {} + constructor( + private readonly koreaInvetmentService: KoreaInvestmentService, + private readonly stockDetailRepository: StockDetailRepository, + ) {} /** * 주식현재가 시세 데이터를 반환하는 함수 @@ -57,16 +61,23 @@ export class StockDetailService { * * @author uuuo3o */ - private formatStockData(stock: InquirePriceOutputData) { - const stockData = new InquirePriceResponseDto(); - stockData.stck_shrn_iscd = stock.stck_shrn_iscd; - stockData.stck_prpr = stock.stck_prpr; - stockData.prdy_vrss = stock.prdy_vrss; - stockData.prdy_vrss_sign = stock.prdy_vrss_sign; - stockData.prdy_ctrt = stock.prdy_ctrt; - stockData.hts_avls = stock.hts_avls; - stockData.per = stock.per; - return stockData; + private async formatStockData( + stock: InquirePriceOutputData, + ): Promise { + const { name } = await this.stockDetailRepository.findOneByCode( + stock.stck_shrn_iscd, + ); + + return { + hts_kor_isnm: name, + stck_shrn_iscd: stock.stck_shrn_iscd, + stck_prpr: stock.stck_prpr, + prdy_vrss: stock.prdy_vrss, + prdy_vrss_sign: stock.prdy_vrss_sign, + prdy_ctrt: stock.prdy_ctrt, + hts_avls: stock.hts_avls, + per: stock.per, + }; } /**