import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, IsEnum, IsArray, IsInt, Min, Max } from 'class-validator';
import { Type, Transform } from 'class-transformer';
import { DocumentStatus } from '../../../database/entities/openapi-document.entity';
export class QueryDocumentDto {
@ApiPropertyOptional({
description: '页码',
example: 1,
minimum: 1,
default: 1,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page?: number = 1;
@ApiPropertyOptional({
description: '每页数量',
example: 10,
minimum: 1,
maximum: 100,
default: 10,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit?: number = 10;
@ApiPropertyOptional({
description: '搜索关键词(搜索名称和描述)',
example: 'petstore',
})
@IsOptional()
@IsString()
search?: string;
@ApiPropertyOptional({
description: '文档状态过滤',
enum: DocumentStatus,
})
@IsOptional()
@IsEnum(DocumentStatus)
status?: DocumentStatus;
@ApiPropertyOptional({
description: '标签过滤(多个标签用逗号分隔)',
example: 'api,rest',
})
@IsOptional()
@Transform(({ value }) => {
if (typeof value === 'string') {
return value.split(',').map(tag => tag.trim()).filter(tag => tag.length > 0);
}
return value;
})
@IsArray()
@IsString({ each: true })
tags?: string[];
@ApiPropertyOptional({
description: '排序字段',
example: 'createdAt',
enum: ['name', 'createdAt', 'updatedAt', 'status'],
default: 'createdAt',
})
@IsOptional()
@IsString()
sortBy?: 'name' | 'createdAt' | 'updatedAt' | 'status' = 'createdAt';
@ApiPropertyOptional({
description: '排序方向',
example: 'DESC',
enum: ['ASC', 'DESC'],
default: 'DESC',
})
@IsOptional()
@IsString()
sortOrder?: 'ASC' | 'DESC' = 'DESC';
}