feat: 支持关卡配置分享
This commit is contained in:
54
src/modules/share/share.controller.ts
Normal file
54
src/modules/share/share.controller.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { ShareService } from './share.service';
|
||||
import { CreateShareDto } from './dto/create-share.dto';
|
||||
import {
|
||||
CreateShareResponseDto,
|
||||
JoinShareResponseDto,
|
||||
} from './dto/share-response.dto';
|
||||
import { ApiResponseDto } from '../../common/dto/api-response.dto';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import type { JwtPayload } from '../../common/guards/jwt-auth.guard';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
|
||||
@ApiTags('分享挑战')
|
||||
@Controller('v1/share')
|
||||
export class ShareController {
|
||||
constructor(private readonly shareService: ShareService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: '创建分享', description: '选择6关+标题,生成分享码' })
|
||||
@ApiResponse({ status: 201, description: '创建成功' })
|
||||
@ApiResponse({ status: 400, description: '参数错误' })
|
||||
async createShare(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Body() dto: CreateShareDto,
|
||||
): Promise<ApiResponseDto<CreateShareResponseDto>> {
|
||||
const data = await this.shareService.createShare(user.sub, dto);
|
||||
return ApiResponseDto.success(data);
|
||||
}
|
||||
|
||||
@Post(':code/join')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({
|
||||
summary: '接受分享',
|
||||
description: '通过分享码加入挑战并获取关卡数据',
|
||||
})
|
||||
@ApiResponse({ status: 200, description: '成功' })
|
||||
@ApiResponse({ status: 404, description: '分享不存在' })
|
||||
async joinShare(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Param('code') code: string,
|
||||
): Promise<ApiResponseDto<JoinShareResponseDto>> {
|
||||
const data = await this.shareService.joinShare(user.sub, code);
|
||||
return ApiResponseDto.success(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user