hello.controller.ts
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
Controller,
Get,
Post,
Patch,
Query,
Delete,
Body,
Param,
Headers,
} from '@nestjs/common';
import {
ApiResponse,
ApiTags,
ApiQuery,
ApiBearerAuth,
ApiBody,
ApiParam,
} from '@nestjs/swagger';
import { HelloService } from './hello.service';
import { Hello, UserRole } from './classes/hello';
@ApiBearerAuth()
@ApiTags('hello')
@Controller('/hello')
export class HelloController {
constructor(private readonly helloService: HelloService) {}
// 查询
@Get()
@ApiQuery({ name: 'name', required: false })
@ApiQuery({ name: 'role', enum: UserRole })
@ApiResponse({
status: 200,
description: 'get ...',
type: Hello,
})
fetch(@Query() { id }, @Headers('token') token): string {
// console.log(url);
return this.helloService.fetch(id);
}
// 创建
@Post()
@ApiBody({ description: '填写更新内容' })
save(@Body() { message }): string {
return this.helloService.save(message);
}
// 更新
@Patch(':id')
@ApiParam({ name: 'id' })
@ApiBody({ description: '请输入message' })
update(@Param() { id }, @Body() { message }): string {
return this.helloService.update(id, message);
}
// 删除
@Delete()
remove(@Query() { id }): string {
return this.helloService.remove(id);
}
}