Skip to content

Commit

Permalink
Merge pull request #107 from boostcampwm-2024/feature/api/stockDetail…
Browse files Browse the repository at this point in the history
…-#54

[BE] 6.02 각 주식 정보 가져오기 API 구현 #54
  • Loading branch information
uuuo3o authored Nov 14, 2024
2 parents 7e209bc + 8c246af commit 7fc8e4e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
13 changes: 13 additions & 0 deletions BE/src/stock/detail/stock-detail.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 5 additions & 2 deletions BE/src/stock/detail/stock-detail.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
15 changes: 15 additions & 0 deletions BE/src/stock/detail/stock-detail.repository.ts
Original file line number Diff line number Diff line change
@@ -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<Stocks> {
constructor(@InjectDataSource() dataSource: DataSource) {
super(Stocks, dataSource.createEntityManager());
}

async findOneByCode(code: string) {
return this.findOne({ where: { code } });
}
}
33 changes: 22 additions & 11 deletions BE/src/stock/detail/stock-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}

/**
* 주식현재가 시세 데이터를 반환하는 함수
Expand Down Expand Up @@ -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<InquirePriceResponseDto> {
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,
};
}

/**
Expand Down

0 comments on commit 7fc8e4e

Please sign in to comment.