|
| 1 | +import { Body, Controller, Delete, Post, Query, Request, Route, Security, Tags } from 'tsoa'; |
| 2 | +import { Request as ExpressRequest } from 'express'; |
| 3 | +import { DefaultNotificationInterface, ResponseFromNotification } from '../DTO/notification_dto'; |
| 4 | +import { NotificationService } from '../service/notification_service'; |
| 5 | +import { TsoaSuccessResponse } from '../config/response_interface'; |
| 6 | + |
| 7 | +@Route('api/notification') |
| 8 | +@Tags('Notification') |
| 9 | +export class NotificationController extends Controller { |
| 10 | + /** |
| 11 | + * 알람 생성 api |
| 12 | + * 알람 type - work_time, work_approve, payment |
| 13 | + * @param body 알람 정보 입력 |
| 14 | + * @summary 알람 생성 API |
| 15 | + */ |
| 16 | + @Post('/new') |
| 17 | + public async sendNotification(@Body() body: DefaultNotificationInterface) { |
| 18 | + const { userId, message, type } = body; |
| 19 | + |
| 20 | + const notification = await NotificationService.sendNotificationService({ |
| 21 | + userId, |
| 22 | + message, |
| 23 | + type, |
| 24 | + }); |
| 25 | + |
| 26 | + return new TsoaSuccessResponse<ResponseFromNotification>(notification); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * 유저 알림 목록 조회 |
| 31 | + * @param req |
| 32 | + * @summary 유저 알림 목록 조회 API |
| 33 | + */ |
| 34 | + @Post('/get') |
| 35 | + @Security('jwt') |
| 36 | + public async getUserNotification(@Request() req: ExpressRequest) { |
| 37 | + const userId = (req.user as unknown as { id: string }).id; |
| 38 | + |
| 39 | + const result = await NotificationService.getNotificationService(userId); |
| 40 | + |
| 41 | + return new TsoaSuccessResponse<ResponseFromNotification[]>(result); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * 알림 삭제 API |
| 46 | + * query - 알림 UUID |
| 47 | + * @param req |
| 48 | + * @param notification_id 삭제할 ID |
| 49 | + * @summary 알림 삭제 API (하나) |
| 50 | +
|
| 51 | + */ |
| 52 | + @Delete('/delete') |
| 53 | + @Security('jwt') |
| 54 | + public async deleteNotification( |
| 55 | + @Request() req: ExpressRequest, |
| 56 | + @Query() notification_id: string, |
| 57 | + ): Promise<TsoaSuccessResponse<string>> { |
| 58 | + const userId = (req.user as unknown as { id: string }).id; |
| 59 | + |
| 60 | + const result = await NotificationService.deleteNotificationService(userId, notification_id); |
| 61 | + |
| 62 | + return new TsoaSuccessResponse<string>(result as string); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * 모든 알림 삭제 API |
| 67 | + * @summary 모든 알림 삭제 API |
| 68 | + * @param req |
| 69 | + */ |
| 70 | + @Delete('/deleteAll') |
| 71 | + @Security('jwt') |
| 72 | + public async deleteAllNotification( |
| 73 | + @Request() req: ExpressRequest, |
| 74 | + ): Promise<TsoaSuccessResponse<number>> { |
| 75 | + const userId = (req.user as unknown as { id: string }).id; |
| 76 | + |
| 77 | + const result: number = await NotificationService.deleteAllNotificationService(userId); |
| 78 | + |
| 79 | + return new TsoaSuccessResponse<number>(result); |
| 80 | + } |
| 81 | +} |
0 commit comments