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

Bug/#361 알림 서비스 오류 해결 #362

Merged
merged 5 commits into from
Dec 4, 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
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/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from '@/auth/auth.controller';
import { GoogleAuthController } from '@/auth/google/googleAuth.controller';
import { GoogleAuthService } from '@/auth/google/googleAuth.service';
import { GoogleStrategy } from '@/auth/google/strategy/google.strategy';
import { AuthController } from '@/auth/auth.controller';
import { SessionSerializer } from '@/auth/session/session.serializer';
import { TesterStrategy } from '@/auth/tester/strategy/tester.strategy';
import { TesterAuthController } from '@/auth/tester/testerAuth.controller';
Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function getFormattedDate(date: Date): string {
return `${date.getFullYear()}-${String(date.getMonth() + 1)
.padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
2,
'0',
)}-${String(date.getDate()).padStart(2, '0')}`;
}
Loading