初始化参股
This commit is contained in:
71
后端/src/user/user.controller.ts
Normal file
71
后端/src/user/user.controller.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto, UpdateUserDto } from './dto/user.dto';
|
||||
import type { CurrentUserData } from '../auth/decorators/current-user.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { Roles } from '../auth/guards/roles.decorator';
|
||||
|
||||
@ApiTags('用户管理')
|
||||
@ApiBearerAuth()
|
||||
@Controller('users')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Post()
|
||||
@Roles('admin')
|
||||
@ApiOperation({ summary: '创建用户(管理员)' })
|
||||
@ApiResponse({ status: 201, description: '创建成功' })
|
||||
create(@Body() createUserDto: CreateUserDto) {
|
||||
return this.userService.create(createUserDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Roles('admin')
|
||||
@ApiOperation({ summary: '获取所有用户(管理员)' })
|
||||
@ApiResponse({ status: 200, description: '获取成功' })
|
||||
findAll() {
|
||||
return this.userService.findAll();
|
||||
}
|
||||
|
||||
@Get('profile')
|
||||
@ApiOperation({ summary: '获取当前用户信息' })
|
||||
@ApiResponse({ status: 200, description: '获取成功' })
|
||||
getProfile(@CurrentUser() user: CurrentUserData) {
|
||||
return this.userService.getUserProfile(user.userId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Roles('admin')
|
||||
@ApiOperation({ summary: '根据ID获取用户(管理员)' })
|
||||
@ApiResponse({ status: 200, description: '获取成功' })
|
||||
@ApiResponse({ status: 404, description: '用户不存在' })
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.userService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('profile')
|
||||
@ApiOperation({ summary: '更新当前用户信息' })
|
||||
@ApiResponse({ status: 200, description: '更新成功' })
|
||||
updateProfile(@CurrentUser() user: CurrentUserData, @Body() updateUserDto: UpdateUserDto) {
|
||||
return this.userService.update(user.userId, updateUserDto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Roles('admin')
|
||||
@ApiOperation({ summary: '更新用户信息(管理员)' })
|
||||
@ApiResponse({ status: 200, description: '更新成功' })
|
||||
@ApiResponse({ status: 404, description: '用户不存在' })
|
||||
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
|
||||
return this.userService.update(+id, updateUserDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Roles('admin')
|
||||
@ApiOperation({ summary: '删除用户(管理员)' })
|
||||
@ApiResponse({ status: 200, description: '删除成功' })
|
||||
@ApiResponse({ status: 404, description: '用户不存在' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.userService.remove(+id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user