|
| 1 | +import { |
| 2 | + Body, |
| 3 | + Controller, |
| 4 | + Delete, |
| 5 | + Get, |
| 6 | + Param, |
| 7 | + ParseIntPipe, |
| 8 | + Post, |
| 9 | + Put, |
| 10 | + Version, |
| 11 | +} from '@nestjs/common'; |
| 12 | +import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; |
| 13 | +import { NoticeDto } from './dto/notice.dto'; |
| 14 | +import { NoticeService } from './notice.service'; |
| 15 | +import { CreateUpdateNoticePayload } from './payload/create-update-notice.payload'; |
| 16 | +import { NoticePreviewDto } from './dto/notice-preview.dto'; |
| 17 | + |
| 18 | +@ApiTags('공지사항 API') |
| 19 | +@Controller('notice') |
| 20 | +export class NoticeController { |
| 21 | + constructor(private readonly noticeService: NoticeService) {} |
| 22 | + |
| 23 | + @Version('1') |
| 24 | + @ApiOperation({ |
| 25 | + summary: '팝업 공지사항 조회 API', |
| 26 | + description: '팝업 공지사항을 조회합니다.', |
| 27 | + }) |
| 28 | + @Get('popup') |
| 29 | + async getPopupNotice(): Promise<NoticeDto> { |
| 30 | + return this.noticeService.getPopupNotice(); |
| 31 | + } |
| 32 | + |
| 33 | + @Version('1') |
| 34 | + @ApiOperation({ |
| 35 | + summary: '팝업 공지사항 등록 API', |
| 36 | + description: '팝업 공지사항을 등록합니다.', |
| 37 | + }) |
| 38 | + @Post('popup/:id') |
| 39 | + async createPopupNotice(@Param('id') id: number): Promise<void> { |
| 40 | + return this.noticeService.createPopupNotice(id); |
| 41 | + } |
| 42 | + |
| 43 | + @Version('1') |
| 44 | + @ApiOperation({ |
| 45 | + summary: '공지사항 생성 API', |
| 46 | + description: '공지사항을 생성합니다.', |
| 47 | + }) |
| 48 | + @Post('') |
| 49 | + async createNotice( |
| 50 | + @Body() payload: CreateUpdateNoticePayload, |
| 51 | + ): Promise<void> { |
| 52 | + return this.noticeService.createNotice(payload); |
| 53 | + } |
| 54 | + |
| 55 | + @Version('1') |
| 56 | + @ApiOperation({ |
| 57 | + summary: '공지사항 수정 API', |
| 58 | + description: '공지사항을 수정합니다.', |
| 59 | + }) |
| 60 | + @Put(':id') |
| 61 | + async updateNotice( |
| 62 | + @Param('id') id: number, |
| 63 | + @Body() payload: CreateUpdateNoticePayload, |
| 64 | + ): Promise<void> { |
| 65 | + return this.noticeService.updateNotice(id, payload); |
| 66 | + } |
| 67 | + |
| 68 | + @Version('1') |
| 69 | + @ApiOperation({ |
| 70 | + summary: '공지사항 삭제 API', |
| 71 | + description: '공지사항을 삭제합니다.', |
| 72 | + }) |
| 73 | + @Delete(':id') |
| 74 | + async deleteNotice(@Param('id') id: number): Promise<void> { |
| 75 | + return this.noticeService.deleteNotice(id); |
| 76 | + } |
| 77 | + |
| 78 | + @Version('1') |
| 79 | + @ApiOperation({ |
| 80 | + summary: '공지사항 조회 api', |
| 81 | + description: '공지사항을 조회합니다.', |
| 82 | + }) |
| 83 | + @ApiOkResponse({ |
| 84 | + description: '전체 공지사항의 id, title, createdAt 필드를 조회합니다.', |
| 85 | + type: [NoticePreviewDto], |
| 86 | + }) |
| 87 | + @Get() |
| 88 | + async getNotice(): Promise<NoticePreviewDto[]> { |
| 89 | + return this.noticeService.getNotice(); |
| 90 | + } |
| 91 | + |
| 92 | + @Version('1') |
| 93 | + @ApiOperation({ |
| 94 | + summary: '공지사항 단일조회 api', |
| 95 | + description: '특정 공지사항을 조회합니다.', |
| 96 | + }) |
| 97 | + @ApiOkResponse({ |
| 98 | + type: NoticeDto, |
| 99 | + }) |
| 100 | + @Get('/:id') |
| 101 | + async getNoticeById( |
| 102 | + @Param('id', ParseIntPipe) id: number, |
| 103 | + ): Promise<NoticeDto> { |
| 104 | + return this.noticeService.getNoticeById(id); |
| 105 | + } |
| 106 | +} |
0 commit comments