|
|
@@ -1,4 +1,48 @@
|
|
|
-import { Controller } from '@nestjs/common';
|
|
|
+import { Controller, Get, HttpStatus, Query } from '@nestjs/common';
|
|
|
+import { UserService } from '../service/user.service';
|
|
|
+import { SearchUserFilter } from '../dto/serach-user.filter';
|
|
|
+import { NoAuth } from '../decorators/no-auth.decorator';
|
|
|
+import { PageResultMapper } from '../mapper/page-result.mapper';
|
|
|
+import { UserVo } from '../vo/user.vo';
|
|
|
+import { UserMapper } from '../mapper/user.mapper';
|
|
|
+import {
|
|
|
+ ApiExtraModels,
|
|
|
+ ApiOkResponse,
|
|
|
+ ApiResponse,
|
|
|
+ getSchemaPath,
|
|
|
+} from '@nestjs/swagger';
|
|
|
+import { PageResult } from '../vo/page-result';
|
|
|
|
|
|
@Controller('user')
|
|
|
-export class UserController {}
|
|
|
+export class UserController {
|
|
|
+ constructor(private readonly userService: UserService) {}
|
|
|
+
|
|
|
+ @Get()
|
|
|
+ @NoAuth()
|
|
|
+ @ApiExtraModels(PageResult, UserVo) // 注册额外模型
|
|
|
+ @ApiOkResponse({
|
|
|
+ description: '分页用户列表',
|
|
|
+ schema: {
|
|
|
+ allOf: [
|
|
|
+ { $ref: getSchemaPath(PageResult) }, // 引用 PageResult 模型
|
|
|
+ {
|
|
|
+ properties: {
|
|
|
+ data: {
|
|
|
+ type: 'array',
|
|
|
+ items: { $ref: getSchemaPath(UserVo) }, // 泛型内容具体化
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ })
|
|
|
+ async search(@Query() searchUserFilter: SearchUserFilter) {
|
|
|
+ const [data, total] = await this.userService.search(searchUserFilter);
|
|
|
+ return PageResultMapper.toPageResult<UserVo>(
|
|
|
+ UserMapper.toVos(data),
|
|
|
+ searchUserFilter.getPage(),
|
|
|
+ searchUserFilter.getSize(),
|
|
|
+ total,
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|