import { Controller, Get, Patch, Body } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; import { UsersService } from './users.service'; import { CurrentUser } from '../../common/decorators/current-user.decorator'; import type { UserPayload } from '../../common/types'; @ApiTags('users') @Controller('users') export class UsersController { constructor(private readonly usersService: UsersService) {} @Get('me') @ApiOperation({ summary: '获取当前用户信息', description: '获取当前登录用户的资料' }) @ApiResponse({ status: 200, description: '用户信息' }) async getProfile(@CurrentUser() user: UserPayload | undefined) { return this.usersService.getProfile(String(user?.id || 'anonymous')); } @Patch('me') @ApiOperation({ summary: '更新用户资料', description: '更新当前用户的资料信息' }) @ApiResponse({ status: 200, description: '更新成功' }) async updateProfile(@CurrentUser() user: UserPayload | undefined, @Body() body: any) { return this.usersService.updateProfile(String(user?.id || 'anonymous'), body); } @Patch('me/preferences') @ApiOperation({ summary: '更新用户偏好', description: '更新当前用户的学习偏好设置' }) @ApiResponse({ status: 200, description: '更新成功' }) async updatePreferences(@CurrentUser() user: UserPayload | undefined, @Body() body: any) { return this.usersService.updatePreferences(String(user?.id || 'anonymous'), body); } }