|
| 1 | +import { |
| 2 | + Controller, |
| 3 | + Get, |
| 4 | + Query, |
| 5 | + DefaultValuePipe, |
| 6 | + ParseIntPipe, |
| 7 | + Res, |
| 8 | + UseGuards, |
| 9 | + HttpStatus, |
| 10 | +} from '@nestjs/common'; |
| 11 | +import { Response } from 'express'; |
| 12 | +import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger'; |
| 13 | +import { AccessTokenGuard } from '@/auth/guards/access-token.guard'; |
| 14 | +import { User } from '@/decorators/user.decorator'; |
| 15 | +import { GetUserNotificationsUseCase } from './usecases/getUserNotifications'; |
| 16 | +import { GetUserNotificationsResult } from './params'; |
| 17 | + |
| 18 | +@ApiTags('Notification') |
| 19 | +@ApiBearerAuth() |
| 20 | +@Controller('notifications') |
| 21 | +export class NotificationController { |
| 22 | + constructor( |
| 23 | + private readonly getUserNotificationsUseCase: GetUserNotificationsUseCase, |
| 24 | + ) {} |
| 25 | + |
| 26 | + // 내 푸시 알림 히스토리를 최근순으로 조회합니다. |
| 27 | + @Get('me') |
| 28 | + @UseGuards(AccessTokenGuard) |
| 29 | + @ApiResponse({ |
| 30 | + status: 200, |
| 31 | + description: 'Get my notifications (recent first) with pagination', |
| 32 | + type: Object, |
| 33 | + }) |
| 34 | + async getMyNotifications( |
| 35 | + @User('id') userId: string, |
| 36 | + @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number, |
| 37 | + @Query('per_page', new DefaultValuePipe(20), ParseIntPipe) perPage: number, |
| 38 | + @Res() res: Response, |
| 39 | + ) { |
| 40 | + const result: GetUserNotificationsResult = |
| 41 | + await this.getUserNotificationsUseCase.execute({ |
| 42 | + userId, |
| 43 | + page, |
| 44 | + limit: perPage, |
| 45 | + }); |
| 46 | + |
| 47 | + return res.status(HttpStatus.OK).json(result); |
| 48 | + } |
| 49 | +} |
0 commit comments