From 6135a8792d76b8c73fe39fe7f4a58c943c1fe462 Mon Sep 17 00:00:00 2001 From: kimminsu Date: Thu, 21 Nov 2024 15:42:35 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A3=BC=EC=8B=9D=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A1=B0=ED=9A=8C=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stock/decorator/stockData.decorator.ts | 14 ++- .../backend/src/stock/stock.controller.ts | 119 ++++++++++-------- 2 files changed, 78 insertions(+), 55 deletions(-) diff --git a/packages/backend/src/stock/decorator/stockData.decorator.ts b/packages/backend/src/stock/decorator/stockData.decorator.ts index 19eb3969..d48dccc1 100644 --- a/packages/backend/src/stock/decorator/stockData.decorator.ts +++ b/packages/backend/src/stock/decorator/stockData.decorator.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable max-lines-per-function */ -import { applyDecorators } from '@nestjs/common'; -import { ApiOperation, ApiParam, ApiQuery, ApiResponse } from '@nestjs/swagger'; -import { StockDataResponse } from '../dto/stockData.response'; +import { applyDecorators } from "@nestjs/common"; +import { ApiOperation, ApiParam, ApiQuery, ApiResponse } from "@nestjs/swagger"; +import { StockDataResponse } from "../dto/stockData.response"; export function ApiGetStockData(summary: string, type: string) { return applyDecorators( @@ -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} 단위 데이터 성공적으로 조회`, diff --git a/packages/backend/src/stock/stock.controller.ts b/packages/backend/src/stock/stock.controller.ts index 5aaf6707..8d75c87c 100644 --- a/packages/backend/src/stock/stock.controller.ts +++ b/packages/backend/src/stock/stock.controller.ts @@ -32,6 +32,7 @@ import { StockDetailService } from './stockDetail.service'; import SessionGuard from '@/auth/session/session.guard'; import { GetUser } from '@/common/decorator/user.decorator'; import { sessionConfig } from '@/configs/session.config'; +import { StockSearchRequest } from '@/stock/dto/stock.request'; import { StockSearchResponse, StockViewsResponse, @@ -46,7 +47,16 @@ import { UserStockResponse, } from '@/stock/dto/userStock.response'; import { User } from '@/user/domain/user.entity'; -import { StockSearchRequest } from '@/stock/dto/stock.request'; + +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 { @@ -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({ @@ -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); + } } From 46ba8aace1cf1d8967d251e5ba4bdf542566943c Mon Sep 17 00:00:00 2001 From: kimminsu Date: Thu, 21 Nov 2024 15:56:24 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=84=20style:=20=ED=81=B0=20?= =?UTF-8?q?=EB=94=B0=EC=98=B4=ED=91=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/stock/decorator/stockData.decorator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/stock/decorator/stockData.decorator.ts b/packages/backend/src/stock/decorator/stockData.decorator.ts index d48dccc1..4941fa61 100644 --- a/packages/backend/src/stock/decorator/stockData.decorator.ts +++ b/packages/backend/src/stock/decorator/stockData.decorator.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable max-lines-per-function */ -import { applyDecorators } from "@nestjs/common"; -import { ApiOperation, ApiParam, ApiQuery, ApiResponse } from "@nestjs/swagger"; -import { StockDataResponse } from "../dto/stockData.response"; +import { applyDecorators } from '@nestjs/common'; +import { ApiOperation, ApiParam, ApiQuery, ApiResponse } from '@nestjs/swagger'; +import { StockDataResponse } from '../dto/stockData.response'; export function ApiGetStockData(summary: string, type: string) { return applyDecorators( From 15549267506b82e0416107b150a522a0ab4134d1 Mon Sep 17 00:00:00 2001 From: kimminsu Date: Thu, 21 Nov 2024 18:08:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=BF=A0=ED=82=A4=20sa?= =?UTF-8?q?meSite=20=EC=98=B5=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/configs/session.config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/backend/src/configs/session.config.ts b/packages/backend/src/configs/session.config.ts index 65c49b96..456bda54 100644 --- a/packages/backend/src/configs/session.config.ts +++ b/packages/backend/src/configs/session.config.ts @@ -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), },