把服务的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 { Controller, Get, Post, Req, Query, Headers, Param, Body } from '@nestjs/common';
|
||||||
import { CreatePostDto } from './post.dto';
|
import { CreatePostDto } from './post.dto';
|
||||||
|
import { DemoService } from './providers/demo/demo.service'
|
||||||
|
|
||||||
|
|
||||||
@Controller('posts')
|
@Controller('posts')
|
||||||
export class PostsController {
|
export class PostsController {
|
||||||
@Get()
|
private readonly demoService;
|
||||||
index(@Headers('authorization') headers, @Query() query) {
|
|
||||||
console.log(headers)
|
constructor(demoService: DemoService) {
|
||||||
console.log(query)
|
this.demoService = demoService
|
||||||
return [
|
|
||||||
{
|
|
||||||
title: 'hello ~'
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
index() {
|
||||||
|
return this.demoService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ -23,7 +26,6 @@ export class PostsController {
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
store(@Body() post: CreatePostDto) {
|
store(@Body() post: CreatePostDto) {
|
||||||
console.log(post)
|
this.demoService.create(post);
|
||||||
return post
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue