import { Controller , Get , Post , Body , Query , Next , Headers , UseGuards , Param , ParseIntPipe , } from '@nestjs/common' ; import { ArticleService } from '../service/article.service' ; import { CreateArticleDto } from '../form/create_article.dto' ; import { UserGuard } from '../../../common/guards/user.guard' ; import { Auth } from '../../../common/interface/Auth' ; import { UpdateArticleDto } from '../form/update_article.dto' ; import { SuccessResponse } from '../../../common/filters/successResponse' ; import { UserError } from '../../../common/filters/userError' ; @ Controller ( 'article/user' ) @ UseGuards ( UserGuard ) export class UserController { constructor ( private readonly articleService ) { } @ Post ( '/create-article' ) async createTag ( @ Body ( ) crateTagDto , @ Headers ( 'auth' ) auth ) { const data = new CreateArticleDto ( crateTagDto ) ; await data . validate ( ) ; return this . articleService . createArticle ( data , auth . user_id ) ; } @ Post ( '/update-article' ) async updateTag ( @ Body ( ) updateTagDto , @ Headers ( 'auth' ) auth ) { const data = new UpdateArticleDto ( updateTagDto ) ; await data . validate ( ) ; await this . articleService . updateArticle ( data , auth . user_id ) ; return SuccessResponse ; } @ Get ( 'detail' ) getArticle ( @ Query ( 'title' ) title , @ Query ( 'article_id' ) articleId , @ Headers ( 'auth' ) auth ) { if ( ! articleId && ! title ) { throw new UserError ( '文章不存在' , 404 ) ; } return this . articleService . getArticle ( auth . user_id , articleId , title ) ; } @ Get ( 'list' ) getList ( @ Query ( 'page' , new ParseIntPipe ( ) ) page , @ Query ( 'size' , new ParseIntPipe ( ) ) size , @ Headers ( 'auth' ) auth , @ Query ( 'category_id' ) categoryId ? , @ Query ( 'secret' ) secret ? , @ Query ( 'tag_id' ) tagId ? , @ Query ( 'title' ) title ? , @ Headers ( 'order' ) order ? ) { return this . articleService . getList ( page , size , auth . user_id , secret , categoryId , tagId , order , title ) ; } @ Get ( 'delete' ) async deleteArticle ( @ Query ( 'article_id' , new ParseIntPipe ( ) ) articleId , @ Headers ( 'auth' ) auth ) { await this . articleService . deleteArticle ( articleId , auth . user_id ) ; return SuccessResponse ; } }