import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { IsInt, IsNotEmpty, IsOptional, IsString, Max, MaxLength, Min, } from 'class-validator'; export class CreateNewsDto { @ApiProperty({ description: '分类ID' }) @IsInt() @Min(1) @Type(() => Number) categoryId: number; @ApiProperty({ description: '新闻标题' }) @IsString() @IsNotEmpty({ message: '标题不能为空' }) @MaxLength(200) title: string; @ApiPropertyOptional({ description: '封面图' }) @IsString() @IsOptional() cover?: string; @ApiPropertyOptional({ description: '简介' }) @IsString() @IsOptional() @MaxLength(500) intro?: string; @ApiProperty({ description: '正文富文本' }) @IsString() @IsNotEmpty({ message: '正文不能为空' }) content: string; @ApiPropertyOptional({ description: '是否置顶 1是0否', default: 0 }) @IsInt() @Min(0) @Max(1) @IsOptional() @Type(() => Number) isTop?: number; @ApiPropertyOptional({ description: '状态 1发布 0草稿', default: 1 }) @IsInt() @Min(0) @Max(1) @IsOptional() @Type(() => Number) status?: number; } export class UpdateNewsDto extends CreateNewsDto {} export class QueryNewsDto { @ApiPropertyOptional({ description: '页码', default: 1 }) @IsInt() @Min(1) @IsOptional() @Type(() => Number) page?: number; @ApiPropertyOptional({ description: '每页数量', default: 10 }) @IsInt() @Min(1) @Max(100) @IsOptional() @Type(() => Number) pageSize?: number; @ApiPropertyOptional({ description: '分类ID' }) @IsInt() @IsOptional() @Type(() => Number) categoryId?: number; @ApiPropertyOptional({ description: '关键词(标题)' }) @IsString() @IsOptional() keyword?: string; }