Skip to content

Commit

Permalink
[chore] Swagger 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
edder773 committed Nov 25, 2024
1 parent ceb2f68 commit 0a55a45
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
26 changes: 25 additions & 1 deletion apps/backend/src/rank/decorator/getRank.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,31 @@ export function getRankResponseDecorator() {
ApiResponse({
status: 200,
description: '랭킹 조회 성공',
type: GetRankSuccessResponseDto
type: GetRankSuccessResponseDto,
examples: {
success: {
summary: '랭킹이 있는 경우',
value: {
code: 200,
message: '현재 랭킹을 조회했습니다.',
data: {
rank: 5,
percentage: 50
}
}
},
noRank: {
summary: '랭킹이 갱신되지 않은 경우',
value: {
code: 200,
message: '현재 랭킹을 조회했습니다.',
data: {
rank: -1,
percentage: null
}
}
}
}
})
);
}
8 changes: 7 additions & 1 deletion apps/backend/src/rank/dto/getRank.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { ApiProperty } from '@nestjs/swagger';
export class GetRankDataDto {
@ApiProperty({
description: '순위',
example: '5'
example: 33
})
rank: number;

@ApiProperty({
description: '백분율',
example: 50
})
percentage: number | null;
}

export class GetRankSuccessResponseDto {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/rank/rank.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export class RankService {
const totalmembers = await this.redisClient.zCard('ranking');
if (!rank) return { rank: -1, percentage: null };
const percentage = ((rank + 1) / totalmembers) * 100;
return { rank: rank + 1, percentage: percentage.toFixed(0) };
return { rank: rank + 1, percentage: percentage == 0 ? 1 : percentage.toFixed(0) };
}
}

0 comments on commit 0a55a45

Please sign in to comment.