add controller

This commit is contained in:
liuyi 2025-05-21 23:14:37 +08:00
parent 552cbf2e57
commit af6906f232

View File

@ -0,0 +1,58 @@
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
Query,
SerializeOptions,
UseInterceptors,
ValidationPipe,
} from '@nestjs/common';
import { pick } from 'lodash';
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
import { CreateCommentDto, QueryCommentDto, QueryCommentTreeDto } from '../dtos/comment.dto';
import { CommentService } from '../services';
@Controller('comment')
@UseInterceptors(AppInterceptor)
export class CommentController {
constructor(protected service: CommentService) {}
@Get('tree')
@SerializeOptions({ groups: ['comment-tree'] })
async tree(@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG)) options: QueryCommentTreeDto) {
return this.service.findTrees(options);
}
@Get()
@SerializeOptions({ groups: ['comment-list'] })
async list(
@Query(
new ValidationPipe({
...pick(DEFAULT_VALIDATION_CONFIG, ['forbidNonWhitelisted', 'whitelist']),
}),
)
options: QueryCommentDto,
) {
return this.service.paginate(options);
}
@Post()
@SerializeOptions({ groups: ['comment-detail'] })
async store(@Body(new ValidationPipe(DEFAULT_VALIDATION_CONFIG)) data: CreateCommentDto) {
return this.service.create(data);
}
@Delete(':id')
@SerializeOptions({ groups: ['comment-detail'] })
async delete(@Param('id', new ParseUUIDPipe()) id: string) {
return this.service.delete(id);
}
}