Skip to content

Commit

Permalink
Feature/#207 - 주식 controller 엔트포인트 통합 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjfcnfw3 authored Nov 21, 2024
2 parents fd56fe0 + 1554926 commit 7b0049f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
2 changes: 2 additions & 0 deletions packages/backend/src/configs/session.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const sessionConfig = {
resave: false,
saveUninitialized: false,
name: process.env.COOKIE_NAME,
secure: true,
sameSite: 'none',
cookie: {
maxAge: Number(process.env.COOKIE_MAX_AGE),
},
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/stock/decorator/stockData.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export function ApiGetStockData(summary: string, type: string) {
type: String,
format: 'date-time',
}),
ApiQuery({
name: 'timeunit',
required: false,
description: '시간 단위',
example: 'minute',
type: String,
enum: ['minute', 'day', 'week', 'month', 'year'],
}),
ApiResponse({
status: 200,
description: `주식의 ${type} 단위 데이터 성공적으로 조회`,
Expand Down
117 changes: 66 additions & 51 deletions packages/backend/src/stock/stock.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ import {
} from '@/stock/dto/userStock.response';
import { User } from '@/user/domain/user.entity';

const TIME_UNIT = {
MINUTE: 'minute',
DAY: 'day',
WEEK: 'week',
MONTH: 'month',
YEAR: 'year',
} as const;

type TIME_UNIT = (typeof TIME_UNIT)[keyof typeof TIME_UNIT];

@Controller('stock')
export class StockController {
constructor(
Expand Down Expand Up @@ -167,61 +177,25 @@ export class StockController {
return await this.stockService.searchStock(request.name);
}

@Get(':stockId/minutely')
@ApiGetStockData('주식 분 단위 데이터 조회 API', '분')
async getStockDataMinutely(
@Param('stockId') stockId: string,
@Query('lastStartTime') lastStartTime?: string,
) {
return this.stockDataMinutelyService.getStockDataMinutely(
stockId,
lastStartTime,
);
}

@Get(':stockId/daily')
@ApiGetStockData('주식 일 단위 데이터 조회 API', '일')
@Get('/:stockId')
@ApiGetStockData('주식 시간 단위 데이터 조회 API', '일')
async getStockDataDaily(
@Param('stockId') stockId: string,
@Query('lastStartTime') lastStartTime?: string,
@Query('timeunit') timeunit: TIME_UNIT = TIME_UNIT.MINUTE,
) {
return this.stockDataDailyService.getStockDataDaily(stockId, lastStartTime);
}

@Get(':stockId/weekly')
@ApiGetStockData('주식 주 단위 데이터 조회 API', '주')
async getStockDataWeekly(
@Param('stockId') stockId: string,
@Query('lastStartTime') lastStartTime?: string,
) {
return this.stockDataWeeklyService.getStockDataWeekly(
stockId,
lastStartTime,
);
}

@Get(':stockId/mothly')
@ApiGetStockData('주식 월 단위 데이터 조회 API', '월')
async getStockDataMonthly(
@Param('stockId') stockId: string,
@Query('lastStartTime') lastStartTime?: string,
) {
return this.stockDataMonthlyService.getStockDataMonthly(
stockId,
lastStartTime,
);
}

@Get(':stockId/yearly')
@ApiGetStockData('주식 연 단위 데이터 조회 API', '연')
async getStockDataYearly(
@Param('stockId') stockId: string,
@Query('lastStartTime') lastStartTime?: string,
) {
return this.stockDataYearlyService.getStockDataYearly(
stockId,
lastStartTime,
);
switch (timeunit) {
case TIME_UNIT.MINUTE:
return this.getMinutelyData(stockId, lastStartTime);
case TIME_UNIT.DAY:
return this.getDailyData(stockId, lastStartTime);
case TIME_UNIT.MONTH:
return this.getStockDataMonthly(stockId, lastStartTime);
case TIME_UNIT.WEEK:
return this.getStockDataWeekly(stockId, lastStartTime);
default:
return this.getStockDataYearly(stockId, lastStartTime);
}
}

@ApiOperation({
Expand Down Expand Up @@ -257,4 +231,45 @@ export class StockController {
async getTopStocksByLosers(@LimitQuery(20) limit: number) {
return await this.stockService.getTopStocksByLosers(limit);
}

private getStockDataYearly(
stockId: string,
lastStartTime: string | undefined,
) {
return this.stockDataYearlyService.getStockDataYearly(
stockId,
lastStartTime,
);
}

private getStockDataWeekly(
stockId: string,
lastStartTime: string | undefined,
) {
return this.stockDataWeeklyService.getStockDataWeekly(
stockId,
lastStartTime,
);
}

private getStockDataMonthly(
stockId: string,
lastStartTime: string | undefined,
) {
return this.stockDataMonthlyService.getStockDataMonthly(
stockId,
lastStartTime,
);
}

private getMinutelyData(stockId: string, lastStartTime?: string) {
return this.stockDataMinutelyService.getStockDataMinutely(
stockId,
lastStartTime,
);
}

private getDailyData(stockId: string, lastStartTime?: string) {
return this.stockDataDailyService.getStockDataDaily(stockId, lastStartTime);
}
}

0 comments on commit 7b0049f

Please sign in to comment.