From f03b55fec4f98ed42b5e35bb093f66e678649a67 Mon Sep 17 00:00:00 2001 From: liuyi Date: Mon, 19 May 2025 14:46:05 +0800 Subject: [PATCH] add content --- .../content/controllers/post.controller.ts | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/modules/content/controllers/post.controller.ts b/src/modules/content/controllers/post.controller.ts index 9b2d01f..bfcd769 100644 --- a/src/modules/content/controllers/post.controller.ts +++ b/src/modules/content/controllers/post.controller.ts @@ -5,64 +5,47 @@ import { Get, Param, ParseIntPipe, + ParseUUIDPipe, Patch, Post, - ValidationPipe, + Query, } from '@nestjs/common'; -import { CreatePostDto } from '@/modules/content/dtos/create-post.dto'; -import { UpdatePostDto } from '@/modules/content/dtos/update-post.dto'; - import { PostService } from '@/modules/content/services/post.service'; +import { PaginateOptions } from '@/modules/database/types'; @Controller('posts') export class PostController { constructor(private postService: PostService) {} @Get() - async index() { - return this.postService.findAll(); + async list(@Query() options: PaginateOptions) { + return this.postService.paginate(options); } @Get(':id') - async show(@Param('id', new ParseIntPipe()) id: number) { - return this.postService.findOne(id); + async show(@Param('id', new ParseIntPipe()) id: string) { + return this.postService.detail(id); } @Post() async store( - @Body( - new ValidationPipe({ - transform: true, - forbidNonWhitelisted: true, - forbidUnknownValues: true, - validationError: { target: false }, - groups: ['create'], - }), - ) - data: CreatePostDto, + @Body() + data: RecordAny, ) { return this.postService.create(data); } @Patch() async update( - @Body( - new ValidationPipe({ - transform: true, - forbidNonWhitelisted: true, - forbidUnknownValues: true, - validationError: { target: false }, - groups: ['update'], - }), - ) - data: UpdatePostDto, + @Body() + data: RecordAny, ) { return this.postService.update(data); } @Delete(':id') - async delete(@Param('id', new ParseIntPipe()) id: number) { + async delete(@Param('id', new ParseUUIDPipe()) id: string) { return this.postService.delete(id); } }