Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 6.02 각 주식 정보 가져오기 API 구현 #54 #107

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 앗 이거도 저희 컨벤션 맞춰야겠네요...! 저는 클래스 이름은 Stock 이런식으로 하구 @Entity('stocks') 이렇게 옵션 추가해서 올렸었거든요
그리고 저희 BaseEntity는 쓰는걸로 결정났었나요??

Copy link
Collaborator Author

@uuuo3o uuuo3o Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 아뇨, BaseEntity 쓰는 거로 결정은 안났고.. 제가 필요한 코드랑 진명님이 작성하신 코드(stock-list 엔티티와 레포지토리 부분)랑 완전 똑같아서 여쭤보니까 상위 폴더에 만들어서 같이 쓰는게 낫겠다는 결론이 나왔어요. 그래서 나중에 합치기 쉽게 복사붙여넣기 해서 가져왔어요..ㅎㅎ
클래스 이름이랑 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
Loading