把服务的DemoService引入到controller来,get路由对应findAll,post对应create,暂时保存在临时对象
This commit is contained in:
parent
b56361bfad
commit
4ee0b7210b
|
@ -1,17 +1,20 @@
|
|||
import { Controller, Get, Post, Req, Query, Headers, Param, Body } from '@nestjs/common';
|
||||
import { CreatePostDto } from './post.dto';
|
||||
import { DemoService } from './providers/demo/demo.service'
|
||||
|
||||
|
||||
@Controller('posts')
|
||||
export class PostsController {
|
||||
private readonly demoService;
|
||||
|
||||
constructor(demoService: DemoService) {
|
||||
this.demoService = demoService
|
||||
}
|
||||
|
||||
|
||||
@Get()
|
||||
index(@Headers('authorization') headers, @Query() query) {
|
||||
console.log(headers)
|
||||
console.log(query)
|
||||
return [
|
||||
{
|
||||
title: 'hello ~'
|
||||
}
|
||||
]
|
||||
index() {
|
||||
return this.demoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
@ -23,7 +26,6 @@ export class PostsController {
|
|||
|
||||
@Post()
|
||||
store(@Body() post: CreatePostDto) {
|
||||
console.log(post)
|
||||
return post
|
||||
this.demoService.create(post);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue