|
| 1 | +import { Transform } from 'class-transformer'; |
| 2 | +import { IsNumber, IsOptional, IsString, Max, Min } from 'class-validator'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @swagger |
| 6 | + * components: |
| 7 | + * schemas: |
| 8 | + * LeaderboardType: |
| 9 | + * type: string |
| 10 | + * description: 리더보드 조회 타입 |
| 11 | + * nullable: true |
| 12 | + * enum: ['user', 'post'] |
| 13 | + * default: 'user' |
| 14 | + */ |
| 15 | +export type LeaderboardType = 'user' | 'post'; |
| 16 | + |
| 17 | +/** |
| 18 | + * @swagger |
| 19 | + * components: |
| 20 | + * schemas: |
| 21 | + * LeaderboardSortType: |
| 22 | + * type: string |
| 23 | + * description: 리더보드 정렬 기준 |
| 24 | + * nullable: true |
| 25 | + * enum: ['viewCount', 'likeCount', 'postCount'] |
| 26 | + * default: 'viewCount' |
| 27 | + */ |
| 28 | +export type LeaderboardSortType = 'viewCount' | 'likeCount' | 'postCount'; |
| 29 | + |
| 30 | +export interface GetLeaderboardQuery { |
| 31 | + type?: LeaderboardType; |
| 32 | + sort?: LeaderboardSortType; |
| 33 | + dateRange?: number; |
| 34 | + limit?: number; |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * @swagger |
| 39 | + * components: |
| 40 | + * schemas: |
| 41 | + * GetLeaderboardQueryDto: |
| 42 | + * type: object |
| 43 | + * properties: |
| 44 | + * type: |
| 45 | + * $ref: '#/components/schemas/LeaderboardType' |
| 46 | + * description: 리더보드 조회 타입 |
| 47 | + * nullable: true |
| 48 | + * default: 'user' |
| 49 | + * sort: |
| 50 | + * $ref: '#/components/schemas/LeaderboardSortType' |
| 51 | + * description: 리더보드 정렬 기준 |
| 52 | + * nullable: true |
| 53 | + * default: 'viewCount' |
| 54 | + * dateRange: |
| 55 | + * type: number |
| 56 | + * description: 리더보드 조회 기간 (일수) |
| 57 | + * nullable: true |
| 58 | + * default: 30 |
| 59 | + * minimum: 1 |
| 60 | + * maximum: 30 |
| 61 | + * limit: |
| 62 | + * type: number |
| 63 | + * description: 리더보드 조회 제한 수 |
| 64 | + * nullable: true |
| 65 | + * default: 10 |
| 66 | + * minimum: 1 |
| 67 | + * maximum: 30 |
| 68 | + */ |
| 69 | +export class GetLeaderboardQueryDto { |
| 70 | + @IsOptional() |
| 71 | + @IsString() |
| 72 | + type?: LeaderboardType; |
| 73 | + |
| 74 | + @IsOptional() |
| 75 | + @IsString() |
| 76 | + sort?: LeaderboardSortType; |
| 77 | + |
| 78 | + @IsOptional() |
| 79 | + @IsNumber() |
| 80 | + @Transform(({ value }) => Number(value)) |
| 81 | + @Min(1) |
| 82 | + @Max(30) |
| 83 | + dateRange?: number; |
| 84 | + |
| 85 | + @IsOptional() |
| 86 | + @IsNumber() |
| 87 | + @Transform(({ value }) => Number(value)) |
| 88 | + @Min(1) |
| 89 | + @Max(30) |
| 90 | + limit?: number; |
| 91 | + |
| 92 | + constructor(type?: LeaderboardType, sort?: LeaderboardSortType, dateRange?: number, limit?: number) { |
| 93 | + this.type = type; |
| 94 | + this.sort = sort; |
| 95 | + this.dateRange = dateRange; |
| 96 | + this.limit = limit; |
| 97 | + } |
| 98 | +} |
0 commit comments