| 1 | import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common' |
| 2 | import { ApiTags } from '@nestjs/swagger' |
| 3 | import { GetToken, TokenInfo } from '@yikart/aitoearn-auth' |
| 4 | import { ApiDoc, ParseObjectIdPipe, UserType, ZodValidationPipe } from '@yikart/common' |
| 5 | import { |
| 6 | ListAideoTasksQueryDto, |
| 7 | SubmitAideoTaskRequest, |
| 8 | submitAideoTaskRequestSchema, |
| 9 | } from './aideo.dto' |
| 10 | import { AideoService } from './aideo.service' |
| 11 | import { |
| 12 | AideoTaskStatusResponseVo, |
| 13 | ListAideoTasksResponseVo, |
| 14 | SubmitAideoTaskResponseVo, |
| 15 | } from './aideo.vo' |
| 16 | |
| 17 | @ApiTags('Me/Ai/Aideo') |
| 18 | @Controller('ai/aideo') |
| 19 | export class AideoController { |
| 20 | constructor(private readonly aideoService: AideoService) {} |
| 21 | |
| 22 | @ApiDoc({ |
| 23 | summary: 'Submit Aideo Task', |
| 24 | body: submitAideoTaskRequestSchema, |
| 25 | response: SubmitAideoTaskResponseVo, |
| 26 | }) |
| 27 | @Post('/tasks') |
| 28 | async submitAideoTask( |
| 29 | @GetToken() token: TokenInfo, |
| 30 | @Body(new ZodValidationPipe(submitAideoTaskRequestSchema)) body: SubmitAideoTaskRequest, |
| 31 | ): Promise<SubmitAideoTaskResponseVo> { |
| 32 | const response = await this.aideoService.submitAideoTask({ |
| 33 | userId: token.id, |
| 34 | userType: UserType.User, |
| 35 | ...body, |
| 36 | }) |
| 37 | return SubmitAideoTaskResponseVo.create(response) |
| 38 | } |
| 39 | |
| 40 | @ApiDoc({ |
| 41 | summary: 'Get Aideo Task Status', |
| 42 | response: AideoTaskStatusResponseVo, |
| 43 | }) |
| 44 | @Get('/tasks/:taskId') |
| 45 | async getAideoTask( |
| 46 | @GetToken() token: TokenInfo, |
| 47 | @Param('taskId', ParseObjectIdPipe) taskId: string, |
| 48 | ): Promise<AideoTaskStatusResponseVo> { |
| 49 | const response = await this.aideoService.getAideoTask({ |
| 50 | userId: token.id, |
| 51 | userType: UserType.User, |
| 52 | taskId, |
| 53 | }) |
| 54 | return AideoTaskStatusResponseVo.create(response) |
| 55 | } |
| 56 | |
| 57 | @ApiDoc({ |
| 58 | summary: 'List Aideo Tasks', |
| 59 | query: ListAideoTasksQueryDto.schema, |
| 60 | response: ListAideoTasksResponseVo, |
| 61 | }) |
| 62 | @Get('/tasks') |
| 63 | async listAideoTasks( |
| 64 | @GetToken() token: TokenInfo, |
| 65 | @Query() query: ListAideoTasksQueryDto, |
| 66 | ): Promise<ListAideoTasksResponseVo> { |
| 67 | const [list, total] = await this.aideoService.listAideoTasks({ |
| 68 | userId: token.id, |
| 69 | userType: UserType.User, |
| 70 | ...query, |
| 71 | }) |
| 72 | return new ListAideoTasksResponseVo(list, total, query) |
| 73 | } |
| 74 | } |
| 75 |