32 lines
666 B
TypeScript
32 lines
666 B
TypeScript
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() {
|
|
return this.demoService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
show(@Param() params) {
|
|
return {
|
|
title: `Post ${params.id}`
|
|
}
|
|
}
|
|
|
|
@Post()
|
|
store(@Body() post: CreatePostDto) {
|
|
this.demoService.create(post);
|
|
}
|
|
}
|