feat:"完成页面接口的对接"

This commit is contained in:
2026-01-29 17:58:19 +08:00
parent 2774a539bf
commit 2b69da3c15
98 changed files with 9504 additions and 592 deletions

View File

@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, HttpCode } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { UserService } from './user.service';
import { CreateUserDto, UpdateUserDto } from './dto/user.dto';
@@ -13,26 +13,45 @@ export class UserController {
constructor(private readonly userService: UserService) {}
@Post()
@HttpCode(200)
@Roles('admin')
@ApiOperation({ summary: '创建用户(管理员)' })
@ApiResponse({ status: 201, description: '创建成功' })
create(@Body() createUserDto: CreateUserDto) {
return this.userService.create(createUserDto);
@ApiResponse({ status: 200, description: '创建成功' })
async create(@Body() createUserDto: CreateUserDto) {
const data = await this.userService.create(createUserDto);
return {
code: 0,
message: '创建成功',
data,
};
}
@Get()
@Roles('admin')
@ApiOperation({ summary: '获取所有用户(管理员)' })
@ApiResponse({ status: 200, description: '获取成功' })
findAll() {
return this.userService.findAll();
async findAll() {
const list = await this.userService.findAll();
return {
code: 0,
message: '获取成功',
data: {
list,
total: list.length,
},
};
}
@Get('profile')
@ApiOperation({ summary: '获取当前用户信息' })
@ApiResponse({ status: 200, description: '获取成功' })
getProfile(@CurrentUser() user: CurrentUserData) {
return this.userService.getUserProfile(user.userId);
async getProfile(@CurrentUser() user: CurrentUserData) {
const data = await this.userService.getUserProfile(user.userId);
return {
code: 0,
message: '获取成功',
data,
};
}
@Get(':id')
@@ -40,15 +59,25 @@ export class UserController {
@ApiOperation({ summary: '根据ID获取用户管理员' })
@ApiResponse({ status: 200, description: '获取成功' })
@ApiResponse({ status: 404, description: '用户不存在' })
findOne(@Param('id') id: string) {
return this.userService.findById(+id);
async findOne(@Param('id') id: string) {
const data = await this.userService.findById(+id);
return {
code: 0,
message: '获取成功',
data,
};
}
@Patch('profile')
@ApiOperation({ summary: '更新当前用户信息' })
@ApiResponse({ status: 200, description: '更新成功' })
updateProfile(@CurrentUser() user: CurrentUserData, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(user.userId, updateUserDto);
async updateProfile(@CurrentUser() user: CurrentUserData, @Body() updateUserDto: UpdateUserDto) {
const data = await this.userService.update(user.userId, updateUserDto);
return {
code: 0,
message: '更新成功',
data,
};
}
@Patch(':id')
@@ -56,8 +85,13 @@ export class UserController {
@ApiOperation({ summary: '更新用户信息(管理员)' })
@ApiResponse({ status: 200, description: '更新成功' })
@ApiResponse({ status: 404, description: '用户不存在' })
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(+id, updateUserDto);
async update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
const data = await this.userService.update(+id, updateUserDto);
return {
code: 0,
message: '更新成功',
data,
};
}
@Delete(':id')
@@ -65,7 +99,11 @@ export class UserController {
@ApiOperation({ summary: '删除用户(管理员)' })
@ApiResponse({ status: 200, description: '删除成功' })
@ApiResponse({ status: 404, description: '用户不存在' })
remove(@Param('id') id: string) {
return this.userService.remove(+id);
async remove(@Param('id') id: string) {
await this.userService.remove(+id);
return {
code: 0,
message: '删除成功',
};
}
}