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
| import { Controller, Post, UseGuards, Body, Get, HttpStatus, Res, Query } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { ArticleService } from './article.service'; import { CreatePostDTO } from './dto/create-post.dto';
@Controller('article') export class ArticleController { constructor( private readonly ariticleService: ArticleService){}
@Get('getArticles') async getPosts(@Res() res) { const posts = await this.ariticleService.getPosts(); return res.status(HttpStatus.OK).json(posts); } @Post('addArticle') @UseGuards(AuthGuard('jwt')) async addArticle(@Res() res, @Body() createPostDTO: CreatePostDTO){ const newPost = await this.ariticleService.addPost(createPostDTO); return res.status(HttpStatus.OK).json({ message: "添加成功!!!", status:200, data: newPost }) }
}
|