add content
This commit is contained in:
parent
eddf8795df
commit
f03b55fec4
@ -5,64 +5,47 @@ import {
|
|||||||
Get,
|
Get,
|
||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
|
ParseUUIDPipe,
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
ValidationPipe,
|
Query,
|
||||||
} from '@nestjs/common';
|
} 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 { PostService } from '@/modules/content/services/post.service';
|
||||||
|
import { PaginateOptions } from '@/modules/database/types';
|
||||||
|
|
||||||
@Controller('posts')
|
@Controller('posts')
|
||||||
export class PostController {
|
export class PostController {
|
||||||
constructor(private postService: PostService) {}
|
constructor(private postService: PostService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async index() {
|
async list(@Query() options: PaginateOptions) {
|
||||||
return this.postService.findAll();
|
return this.postService.paginate(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async show(@Param('id', new ParseIntPipe()) id: number) {
|
async show(@Param('id', new ParseIntPipe()) id: string) {
|
||||||
return this.postService.findOne(id);
|
return this.postService.detail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async store(
|
async store(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
data: RecordAny,
|
||||||
transform: true,
|
|
||||||
forbidNonWhitelisted: true,
|
|
||||||
forbidUnknownValues: true,
|
|
||||||
validationError: { target: false },
|
|
||||||
groups: ['create'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: CreatePostDto,
|
|
||||||
) {
|
) {
|
||||||
return this.postService.create(data);
|
return this.postService.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch()
|
@Patch()
|
||||||
async update(
|
async update(
|
||||||
@Body(
|
@Body()
|
||||||
new ValidationPipe({
|
data: RecordAny,
|
||||||
transform: true,
|
|
||||||
forbidNonWhitelisted: true,
|
|
||||||
forbidUnknownValues: true,
|
|
||||||
validationError: { target: false },
|
|
||||||
groups: ['update'],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
data: UpdatePostDto,
|
|
||||||
) {
|
) {
|
||||||
return this.postService.update(data);
|
return this.postService.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
async delete(@Param('id', new ParseIntPipe()) id: number) {
|
async delete(@Param('id', new ParseUUIDPipe()) id: string) {
|
||||||
return this.postService.delete(id);
|
return this.postService.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user