Skip to content

Commit

Permalink
feat: query with limit & offset
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuWang committed Oct 29, 2023
1 parent eabd4c6 commit 8a1e2e5
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/coffees/coffees.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,34 @@ import {
Param,
Patch,
Post,
Query,
// Put,
Res,
// Res,
} from '@nestjs/common';

// nest generate controller 命令行创建 controller
// 简写 nest g co, 如果不需要测试 nest g co--no - spec

@Controller('coffees')
export class CoffeesController {
@Get()
// @Get()
// @Get('test') // 也可以写成 @Get('test'),这样就会变成 /coffees/test
// findAll() {
// return 'This action returns all coffees';
findAll(@Res() response) {
// 使用底层库的响应对象返回结果 nestjs 默认底层库为 express
// 但这种方式并不推荐,因为这样就会失去 nestjs 的优势,而且测试也会变得困难,要模拟 response 对象
response.status(210).send('This action returns all coffees');
// return 'This action returns all coffees';
// }

// @Get()
// findAll(@Res() response) {
// 使用底层库的响应对象返回结果 nestjs 默认底层库为 express
// 但这种方式并不推荐,因为这样就会失去 nestjs 的优势,而且测试也会变得困难,要模拟 response 对象
// response.status(210).send('This action returns all coffees');
// }

@Get()
findAll(@Query() paginationQuery) {
// return `This action returns all coffees. Limit: ${paginationQuery.limit}, Offset: ${paginationQuery.offset}`;
const { limit, offset } = paginationQuery;
return `This action returns all coffees. Limit: ${limit}, Offset: ${offset}`;
}

@Get(':id')
Expand Down

0 comments on commit 8a1e2e5

Please # to comment.