Skip to content

Commit

Permalink
Feature/#369 eslint, 알림 string 리턴 수정, swagger 성공하게 조건 변경 (#370)
Browse files Browse the repository at this point in the history
* 💄 style: eslint 깨지는 파일 수정

* 📝 docs: stockId 잘못 들어 있던 데코레이터 수정

* 📝 docs: response alarmresponse 로 수정

* 🐛 fix: bigint가 런타임때는 string으로 작동, decimal 15,2로 변경

* 🐛 fix: stock id를 이상하게 호출하는 문제 해결, express 와 동일한 구조로 되어있어 라우터 등록 순서에 영향 받는 다는 것을 간과함

* 🐛 fix: put 에러 수정, alarmDate -\> alarmExpiredDate로 명확화

* 📝 docs: reqeust 업데이트

* 🐛 fix: alarmDate 업데이트

* 🐛 fix: alarmExpiredDate로 변환, 이에 맞춰 docs도 업데이트

* ✨ feat: 알림 서비스 검증 로직 구현

* 📝 docs: 알림 docs 에러 수정

* 🐛 fix: expired date 논리 오류 수정

* 📝 docs: 원 추가

* 🐛 fix: api/alarm/stock 받아올 때 중복 stock 수정

* 📝 docs: swagger 성공하게 변경

* 💄 style: 줄 제약으로 인한 커스텀 데코레이터 적용

* 🐛 fix: response에 number 추가
  • Loading branch information
swkim12345 authored Dec 4, 2024
1 parent 53dec2b commit 9add4dc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
32 changes: 5 additions & 27 deletions packages/backend/src/alarm/alarm.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
UseGuards,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiResponse,
} from '@nestjs/swagger';
import { AlarmService } from './alarm.service';
import { WrongAlarmApi } from './decorator/wrong.decorator';
import { AlarmRequest } from './dto/alarm.request';
import { AlarmResponse, AlarmSuccessResponse } from './dto/alarm.response';
import SessionGuard from '@/auth/session/session.guard';
Expand All @@ -36,18 +36,7 @@ export class AlarmController {
description: '알림 생성 완료',
type: AlarmResponse,
})
@ApiBadRequestResponse({
description: '유효하지 않은 알람 입력값으로 인해 예외가 발생했습니다.',
schema: {
type: 'object',
properties: {
statusCode: { type: 'number', example: 400 },
message: { type: 'string', example: '알람 조건을 다시 확인해주세요.' },
error: { type: 'string', example: 'Bad Request' },
},
},
})
@UseGuards(SessionGuard)
@WrongAlarmApi()
async create(
@Body() alarmRequest: AlarmRequest,
@GetUser() user: User,
Expand Down Expand Up @@ -84,13 +73,13 @@ export class AlarmController {
type: [AlarmResponse],
})
@ApiParam({
name: 'id',
name: 'stockId',
type: String,
description: '주식 아이디',
example: '005930',
})
@UseGuards(SessionGuard)
async getByStockId(@Param('id') stockId: string, @GetUser() user: User) {
async getByStockId(@Param('stockId') stockId: string, @GetUser() user: User) {
const userId = user.id;

return await this.alarmService.findByStockId(stockId, userId);
Expand Down Expand Up @@ -131,18 +120,7 @@ export class AlarmController {
description: '알림 아이디',
example: 1,
})
@ApiBadRequestResponse({
description: '유효하지 않은 알람 입력값으로 인해 예외가 발생했습니다.',
schema: {
type: 'object',
properties: {
statusCode: { type: 'number', example: 400 },
message: { type: 'string', example: '알람 조건을 다시 확인해주세요.' },
error: { type: 'string', example: 'Bad Request' },
},
},
})
@UseGuards(SessionGuard)
@WrongAlarmApi()
async update(
@Param('id') alarmId: number,
@Body() updateData: AlarmRequest,
Expand Down
23 changes: 23 additions & 0 deletions packages/backend/src/alarm/decorator/wrong.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { applyDecorators, UseGuards } from '@nestjs/common';
import { ApiBadRequestResponse } from '@nestjs/swagger';
import SessionGuard from '@/auth/session/session.guard';

export const WrongAlarmApi = () => {
return applyDecorators(
ApiBadRequestResponse({
description: '유효하지 않은 알람 입력값으로 인해 예외가 발생했습니다.',
schema: {
type: 'object',
properties: {
statusCode: { type: 'number', example: 400 },
message: {
type: 'string',
example: '알람 조건을 다시 확인해주세요.',
},
error: { type: 'string', example: 'Bad Request' },
},
},
}),
UseGuards(SessionGuard),
);
};
4 changes: 2 additions & 2 deletions packages/backend/src/alarm/dto/alarm.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export class AlarmRequest {

@ApiProperty({
description: '목표 가격',
example: 150.0,
example: 100000,
required: false,
})
targetPrice?: number;

@ApiProperty({
description: '목표 거래량',
example: 1000,
example: 1000000000,
required: false,
})
targetVolume?: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/alarm/dto/alarm.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class AlarmResponse {
constructor(alarm: Alarm) {
this.alarmId = alarm.id;
this.stockId = alarm.stock.id;
this.targetPrice = alarm.targetPrice;
this.targetVolume = alarm.targetVolume;
this.targetPrice = Number(alarm.targetPrice);
this.targetVolume = Number(alarm.targetVolume);
this.alarmExpiredDate = alarm.alarmExpiredDate;
}
}
Expand Down

0 comments on commit 9add4dc

Please sign in to comment.