forked from xiangwang25/whale-town-end-v2
Initial WhaleTown V2 backend
This commit is contained in:
80
src/business/player/player.controller.ts
Normal file
80
src/business/player/player.controller.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Body, Controller, Get, HttpStatus, Patch, Res, UseGuards, UsePipes, ValidationPipe } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse as SwaggerApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { Response } from 'express';
|
||||
import { CurrentUser } from '../../gateway/auth/current_user.decorator';
|
||||
import { JwtAuthGuard } from '../../gateway/auth/jwt_auth.guard';
|
||||
import { JwtPayload } from '../../core/login_core/login_core.service';
|
||||
import { PlayerStateService } from './player_state.service';
|
||||
import { EconomyService } from './economy.service';
|
||||
import { UpdatePlayerAppearanceDto } from './dto/update_player_appearance.dto';
|
||||
import { UpdatePlayerProfileAssetsDto } from './dto/update_player_profile_assets.dto';
|
||||
import { UpdatePlayerSettingsDto } from './dto/update_player_settings.dto';
|
||||
|
||||
@ApiTags('player')
|
||||
@ApiBearerAuth()
|
||||
@Controller('player')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class PlayerController {
|
||||
constructor(
|
||||
private readonly playerStateService: PlayerStateService,
|
||||
private readonly economyService: EconomyService,
|
||||
) {}
|
||||
|
||||
@ApiOperation({ summary: '获取当前玩家快照' })
|
||||
@SwaggerApiResponse({ status: 200, description: '玩家快照获取成功' })
|
||||
@Get('snapshot')
|
||||
async getSnapshot(@CurrentUser() user: JwtPayload, @Res() res: Response): Promise<void> {
|
||||
const data = await this.playerStateService.getSnapshot(BigInt(user.sub));
|
||||
res.status(HttpStatus.OK).json({ success: true, data, message: '玩家快照获取成功' });
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: '获取当前玩家钱包' })
|
||||
@SwaggerApiResponse({ status: 200, description: '钱包获取成功' })
|
||||
@Get('wallet')
|
||||
async getWallet(@CurrentUser() user: JwtPayload, @Res() res: Response): Promise<void> {
|
||||
const data = await this.economyService.getWallet(BigInt(user.sub));
|
||||
res.status(HttpStatus.OK).json({ success: true, data, message: '钱包获取成功' });
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: '更新当前穿戴皮肤' })
|
||||
@ApiBody({ type: UpdatePlayerAppearanceDto })
|
||||
@SwaggerApiResponse({ status: 200, description: '外观更新成功' })
|
||||
@Patch('appearance')
|
||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
||||
async updateAppearance(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Body() dto: UpdatePlayerAppearanceDto,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const data = await this.playerStateService.updateAppearance(BigInt(user.sub), dto.skin_id);
|
||||
res.status(HttpStatus.OK).json({ success: true, data, message: '外观更新成功' });
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: '更新当前玩家设置' })
|
||||
@ApiBody({ type: UpdatePlayerSettingsDto })
|
||||
@SwaggerApiResponse({ status: 200, description: '设置更新成功' })
|
||||
@Patch('settings')
|
||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
||||
async updateSettings(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Body() dto: UpdatePlayerSettingsDto,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const data = await this.playerStateService.updateSettings(BigInt(user.sub), dto.settings);
|
||||
res.status(HttpStatus.OK).json({ success: true, data, message: '设置更新成功' });
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: '更新当前玩家头像或自定义皮肤资源' })
|
||||
@ApiBody({ type: UpdatePlayerProfileAssetsDto })
|
||||
@SwaggerApiResponse({ status: 200, description: '玩家资源更新成功' })
|
||||
@Patch('profile-assets')
|
||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
||||
async updateProfileAssets(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Body() dto: UpdatePlayerProfileAssetsDto,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const data = await this.playerStateService.updateProfileAssets(BigInt(user.sub), dto);
|
||||
res.status(HttpStatus.OK).json({ success: true, data, message: '玩家资源更新成功' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user