2026-05-17 00:39:46 +08:00
|
|
|
import { Controller, Get, Patch, Body } from '@nestjs/common';
|
2026-05-09 18:57:33 +08:00
|
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
|
2026-05-09 18:25:04 +08:00
|
|
|
import { UsersService } from './users.service';
|
|
|
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
|
|
|
import type { UserPayload } from '../../common/types';
|
|
|
|
|
|
|
|
|
|
@ApiTags('users')
|
|
|
|
|
@Controller('users')
|
2026-05-09 18:57:33 +08:00
|
|
|
@ApiBearerAuth()
|
2026-05-09 18:25:04 +08:00
|
|
|
export class UsersController {
|
|
|
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
|
|
|
|
|
|
@Get('me')
|
2026-05-09 18:57:33 +08:00
|
|
|
@ApiOperation({ summary: '获取当前用户信息' })
|
2026-05-09 18:25:04 +08:00
|
|
|
@ApiResponse({ status: 200, description: '用户信息' })
|
2026-05-09 18:57:33 +08:00
|
|
|
async getProfile(@CurrentUser() user: UserPayload) {
|
|
|
|
|
return this.usersService.getProfile(String(user.id));
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch('me')
|
2026-05-09 18:57:33 +08:00
|
|
|
@ApiOperation({ summary: '更新用户资料' })
|
|
|
|
|
async updateProfile(@CurrentUser() user: UserPayload, @Body() body: any) {
|
|
|
|
|
return this.usersService.updateProfile(String(user.id), body);
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch('me/preferences')
|
2026-05-09 18:57:33 +08:00
|
|
|
@ApiOperation({ summary: '更新用户偏好' })
|
|
|
|
|
async updatePreferences(@CurrentUser() user: UserPayload, @Body() body: any) {
|
|
|
|
|
return this.usersService.updatePreferences(String(user.id), body);
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
}
|