- 基于 NestJS + TypeScript + MySQL + Redis 架构 - 完整的模块化设计(认证、用户、小组、游戏、预约等) - JWT 认证和 RBAC 权限控制系统 - Docker 容器化部署支持 - 添加 CLAUDE.md 项目开发指南 - 配置 .gitignore 忽略文件 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
|
|
import { GamesService } from './games.service';
|
|
import { CreateGameDto, UpdateGameDto, SearchGameDto } from './dto/game.dto';
|
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|
import { Public } from '../../common/decorators/public.decorator';
|
|
|
|
@ApiTags('games')
|
|
@Controller('games')
|
|
export class GamesController {
|
|
constructor(private readonly gamesService: GamesService) {}
|
|
|
|
@Public()
|
|
@Get()
|
|
@ApiOperation({ summary: '获取游戏列表' })
|
|
@ApiResponse({ status: 200, description: '获取成功' })
|
|
@ApiQuery({ name: 'keyword', required: false, description: '搜索关键词' })
|
|
@ApiQuery({ name: 'platform', required: false, description: '游戏平台' })
|
|
@ApiQuery({ name: 'tag', required: false, description: '游戏标签' })
|
|
@ApiQuery({ name: 'page', required: false, description: '页码' })
|
|
@ApiQuery({ name: 'limit', required: false, description: '每页数量' })
|
|
async findAll(@Query() searchDto: SearchGameDto) {
|
|
return this.gamesService.findAll(searchDto);
|
|
}
|
|
|
|
@Public()
|
|
@Get('popular')
|
|
@ApiOperation({ summary: '获取热门游戏' })
|
|
@ApiResponse({ status: 200, description: '获取成功' })
|
|
@ApiQuery({ name: 'limit', required: false, description: '数量限制' })
|
|
async findPopular(@Query('limit') limit?: number) {
|
|
return this.gamesService.findPopular(limit);
|
|
}
|
|
|
|
@Public()
|
|
@Get('tags')
|
|
@ApiOperation({ summary: '获取所有游戏标签' })
|
|
@ApiResponse({ status: 200, description: '获取成功' })
|
|
async getTags() {
|
|
return this.gamesService.getTags();
|
|
}
|
|
|
|
@Public()
|
|
@Get('platforms')
|
|
@ApiOperation({ summary: '获取所有游戏平台' })
|
|
@ApiResponse({ status: 200, description: '获取成功' })
|
|
async getPlatforms() {
|
|
return this.gamesService.getPlatforms();
|
|
}
|
|
|
|
@Public()
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取游戏详情' })
|
|
@ApiResponse({ status: 200, description: '获取成功' })
|
|
async findOne(@Param('id') id: string) {
|
|
return this.gamesService.findOne(id);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post()
|
|
@ApiOperation({ summary: '创建游戏' })
|
|
@ApiResponse({ status: 201, description: '创建成功' })
|
|
async create(@Body() createGameDto: CreateGameDto) {
|
|
return this.gamesService.create(createGameDto);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Put(':id')
|
|
@ApiOperation({ summary: '更新游戏信息' })
|
|
@ApiResponse({ status: 200, description: '更新成功' })
|
|
async update(@Param('id') id: string, @Body() updateGameDto: UpdateGameDto) {
|
|
return this.gamesService.update(id, updateGameDto);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除游戏' })
|
|
@ApiResponse({ status: 200, description: '删除成功' })
|
|
async remove(@Param('id') id: string) {
|
|
return this.gamesService.remove(id);
|
|
}
|
|
}
|