Skip to content

Commit

Permalink
Merge branch 'dev-be' into bug/#345
Browse files Browse the repository at this point in the history
  • Loading branch information
xjfcnfw3 authored Dec 4, 2024
2 parents 0ca4bee + 67c5e21 commit 57dd091
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
78 changes: 39 additions & 39 deletions packages/backend/src/alarm/alarm.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ export class AlarmController {
return await this.alarmService.create(alarmRequest, userId);
}

@Get('user')
@ApiOperation({
summary: '사용자별 알림 조회',
description: '사용자 아이디를 기준으로 모든 알림을 조회한다.',
})
@ApiOkResponse({
description: '사용자에게 등록되어 있는 모든 알림 조회',
type: [AlarmResponse],
})
@UseGuards(SessionGuard)
async getByUserId(@GetUser() user: User) {
const userId = user.id;

return await this.alarmService.findByUserId(userId);
}

@Get('stock/:stockId')
@ApiOperation({
summary: '주식별 알림 조회',
description: '주식 아이디를 기준으로 알림을 조회한다.',
})
@ApiOkResponse({
description:
'주식 아이디에 등록되어 있는 알림 중 유저에 해당하는 알림 조회',
type: [AlarmResponse],
})
@ApiParam({
name: 'id',
type: String,
description: '주식 아이디',
example: '005930',
})
@UseGuards(SessionGuard)
async getByStockId(@Param('id') stockId: string, @GetUser() user: User) {
const userId = user.id;

return await this.alarmService.findByStockId(stockId, userId);
}

@Get(':id')
@ApiOperation({
summary: '등록된 알림 확인',
Expand Down Expand Up @@ -110,43 +149,4 @@ export class AlarmController {

return new AlarmSuccessResponse('알림 삭제를 성공했습니다.');
}

@Get('user')
@ApiOperation({
summary: '사용자별 알림 조회',
description: '사용자 아이디를 기준으로 모든 알림을 조회한다.',
})
@ApiOkResponse({
description: '사용자에게 등록되어 있는 모든 알림 조회',
type: [AlarmResponse],
})
@UseGuards(SessionGuard)
async getByUserId(@GetUser() user: User) {
const userId = user.id;

return await this.alarmService.findByUserId(userId);
}

@Get('stock/:stockId')
@ApiOperation({
summary: '주식별 알림 조회',
description: '주식 아이디를 기준으로 알림을 조회한다.',
})
@ApiOkResponse({
description:
'주식 아이디에 등록되어 있는 알림 중 유저에 해당하는 알림 조회',
type: [AlarmResponse],
})
@ApiParam({
name: 'id',
type: String,
description: '주식 아이디',
example: '005930',
})
@UseGuards(SessionGuard)
async getByStockId(@Param('stockId') stockId: string, @GetUser() user: User) {
const userId = user.id;

return await this.alarmService.findByStockId(stockId, userId);
}
}
5 changes: 3 additions & 2 deletions packages/backend/src/alarm/alarm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export class AlarmService {
return result.map((val) => new AlarmResponse(val));
}

async findByStockId(stockId: string, userId: number): Promise<Alarm[]> {
return await this.alarmRepository.find({
async findByStockId(stockId: string, userId: number) {
const result = await this.alarmRepository.find({
where: { stock: { id: stockId }, user: { id: userId } },
relations: ['user', 'stock'],
});
return result.map((val) => new AlarmResponse(val));
}

async findOne(id: number) {
Expand Down
8 changes: 7 additions & 1 deletion packages/backend/src/alarm/domain/alarm.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export class Alarm {
@Column({ type: 'int', name: 'target_price', nullable: true })
targetPrice?: number;

@Column({ type: 'bigint', name: 'target_volume', nullable: true })
@Column({
type: 'decimal',
precision: 15,
scale: 2,
name: 'target_volume',
nullable: true,
})
targetVolume?: number;

@Column({ type: 'timestamp', name: 'alarm_date', nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export function isTodayWeekend() {
const today = new Date();
const day = today.getDay();
return day === 0 || day === 6;
}
}

0 comments on commit 57dd091

Please sign in to comment.