| 1 | import { Body, Controller, Get, Post, Query } from '@nestjs/common' |
| 2 | import { ApiTags } from '@nestjs/swagger' |
| 3 | import { GetToken, TokenInfo } from '@yikart/aitoearn-auth' |
| 4 | import { ApiDoc } from '@yikart/common' |
| 5 | import { |
| 6 | CallEngagementFunctionBodyDto, |
| 7 | CreateEngagementCommentBodyDto, |
| 8 | EngagementCommentsQueryDto, |
| 9 | EngagementExecutionQueryDto, |
| 10 | } from './engagement.dto' |
| 11 | import { EngagementService } from './engagement.service' |
| 12 | import { ChannelCommentListVo, ChannelEngagementActionVo } from './engagement.vo' |
| 13 | |
| 14 | @ApiTags('Channels/Engagement') |
| 15 | @Controller({ path: '/channels/engagement', version: '2' }) |
| 16 | export class EngagementController { |
| 17 | constructor(private readonly engagementService: EngagementService) {} |
| 18 | |
| 19 | @ApiDoc({ |
| 20 | summary: '获取评论列表', |
| 21 | description: '获取指定作品的评论列表', |
| 22 | query: EngagementCommentsQueryDto.schema, |
| 23 | response: ChannelCommentListVo, |
| 24 | }) |
| 25 | @Get('/comments') |
| 26 | async listComments( |
| 27 | @GetToken() token: TokenInfo, |
| 28 | @Query() query: EngagementCommentsQueryDto, |
| 29 | ) { |
| 30 | return ChannelCommentListVo.create( |
| 31 | await this.engagementService.listComments( |
| 32 | token.id, |
| 33 | query.platform, |
| 34 | query.platformWorkId, |
| 35 | query.accountId, |
| 36 | query.pagination, |
| 37 | ), |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | @ApiDoc({ |
| 42 | summary: '发表评论', |
| 43 | description: '在指定作品下发表评论', |
| 44 | query: EngagementExecutionQueryDto.schema, |
| 45 | body: CreateEngagementCommentBodyDto.schema, |
| 46 | response: ChannelEngagementActionVo, |
| 47 | }) |
| 48 | @Post('/comments') |
| 49 | async createComment( |
| 50 | @GetToken() token: TokenInfo, |
| 51 | @Query() query: EngagementExecutionQueryDto, |
| 52 | @Body() body: CreateEngagementCommentBodyDto, |
| 53 | ) { |
| 54 | return ChannelEngagementActionVo.create( |
| 55 | await this.engagementService.createComment( |
| 56 | token.id, |
| 57 | query.accountId, |
| 58 | body.platform, |
| 59 | body.platformWorkId, |
| 60 | body.content, |
| 61 | body.parentCommentId, |
| 62 | ), |
| 63 | ) |
| 64 | } |
| 65 | |
| 66 | @ApiDoc({ |
| 67 | summary: '调用互动函数', |
| 68 | description: '调用平台支持的互动函数', |
| 69 | query: EngagementExecutionQueryDto.schema, |
| 70 | body: CallEngagementFunctionBodyDto.schema, |
| 71 | response: ChannelEngagementActionVo, |
| 72 | }) |
| 73 | @Post('/function') |
| 74 | async callFunction( |
| 75 | @GetToken() token: TokenInfo, |
| 76 | @Query() query: EngagementExecutionQueryDto, |
| 77 | @Body() body: CallEngagementFunctionBodyDto, |
| 78 | ) { |
| 79 | return ChannelEngagementActionVo.create( |
| 80 | await this.engagementService.callFunction( |
| 81 | token.id, |
| 82 | query.accountId, |
| 83 | body, |
| 84 | ), |
| 85 | ) |
| 86 | } |
| 87 | } |
| 88 |