| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2024-06-17 19:19:20 |
| 4 | * @LastEditTime: 2024-12-23 12:45:22 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: 发布 |
| 7 | */ |
| 8 | import { Body, Controller, Get, Param, Post, Query, Delete } from '@nestjs/common'; |
| 9 | import { ApiOperation, ApiTags } from '@nestjs/swagger'; |
| 10 | import { ParamsValidationPipe } from 'src/validation.pipe'; |
| 11 | import { TokenInfo } from 'src/auth/interfaces/auth.interfaces'; |
| 12 | import { GetToken } from 'src/auth/auth.guard'; |
| 13 | import { PublishService } from './publish.service'; |
| 14 | import { CreatePublishDto, PubRecordListDto } from './dto/publish.dto'; |
| 15 | import { TableDto } from 'src/global/dto/table.dto'; |
| 16 | import { PubStatus } from 'src/db/schema/pubRecord.schema'; |
| 17 | |
| 18 | @ApiTags('发布') |
| 19 | @Controller('publish') |
| 20 | export class PublishController { |
| 21 | constructor(private readonly pubRecordService: PublishService) {} |
| 22 | |
| 23 | @ApiOperation({ |
| 24 | description: '创建发布记录', |
| 25 | summary: '创建发布记录', |
| 26 | }) |
| 27 | @Post() |
| 28 | async createPubRecord( |
| 29 | @GetToken() token: TokenInfo, |
| 30 | @Body(new ParamsValidationPipe()) body: CreatePublishDto, |
| 31 | ) { |
| 32 | console.log(body) |
| 33 | const res = await this.pubRecordService.createPubRecord({ |
| 34 | userId: token.id, |
| 35 | ...body, |
| 36 | }); |
| 37 | return res; |
| 38 | } |
| 39 | |
| 40 | @ApiOperation({ |
| 41 | description: '获取发布记录列表', |
| 42 | summary: '获取发布记录列表', |
| 43 | }) |
| 44 | @Get('list/:pageNo/:pageSize') |
| 45 | async getPubRecordList( |
| 46 | @GetToken() token: TokenInfo, |
| 47 | @Param(new ParamsValidationPipe()) param: TableDto, |
| 48 | @Query(new ParamsValidationPipe()) query: PubRecordListDto, |
| 49 | ) { |
| 50 | const res = await this.pubRecordService.getPubRecordList( |
| 51 | token.id, |
| 52 | param, |
| 53 | query, |
| 54 | ); |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | @ApiOperation({ |
| 59 | description: '获取草稿列表', |
| 60 | summary: '获取草稿列表', |
| 61 | }) |
| 62 | @Get('drafts/list/:pageNo/:pageSize') |
| 63 | async getPubRecordDraftsList( |
| 64 | @GetToken() token: TokenInfo, |
| 65 | @Param(new ParamsValidationPipe()) param: TableDto, |
| 66 | @Query(new ParamsValidationPipe()) query: PubRecordListDto, |
| 67 | ) { |
| 68 | const res = await this.pubRecordService.getPubRecordDraftsList( |
| 69 | token.id, |
| 70 | param, |
| 71 | query, |
| 72 | ); |
| 73 | return res; |
| 74 | } |
| 75 | |
| 76 | @ApiOperation({ |
| 77 | description: '更新发布记录状态', |
| 78 | summary: '更新发布记录状态', |
| 79 | }) |
| 80 | @Post('status/:id') |
| 81 | async updatePubRecordStatus( |
| 82 | @GetToken() token: TokenInfo, |
| 83 | @Param('id', new ParamsValidationPipe()) id: number, |
| 84 | @Body('status', new ParamsValidationPipe()) status: PubStatus, |
| 85 | ) { |
| 86 | const res = await this.pubRecordService.updatePubRecordStatus(id, status); |
| 87 | return res; |
| 88 | } |
| 89 | |
| 90 | @ApiOperation({ |
| 91 | description: '删除发布记录', |
| 92 | summary: '删除发布记录', |
| 93 | }) |
| 94 | @Delete(':id') |
| 95 | async deletePubRecord( |
| 96 | @GetToken() token: TokenInfo, |
| 97 | @Param('id', new ParamsValidationPipe()) id: number, |
| 98 | ) { |
| 99 | const res = await this.pubRecordService.deletePubRecordById(id); |
| 100 | return res; |
| 101 | } |
| 102 | } |
| 103 |