Skip to content

Commit

Permalink
Merge pull request #61 from tscenping/jangcho
Browse files Browse the repository at this point in the history
feat(users): change '/ranks' without guards, pagination to chunked data
  • Loading branch information
cjho0316 authored Dec 6, 2023
2 parents 3eb5239 + b2e7601 commit 580c439
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
11 changes: 4 additions & 7 deletions src/users/ranks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ export class RanksService {
@InjectRedis() private readonly redis: Redis,
) {}

async findRanksWithPage(page: number): Promise<RankUserResponseDto> {
async findRanksWithPage(): Promise<RankUserResponseDto> {
//userIDRanking: [userId, userId, userId, ...]


const userRanking = await this.redis.zrevrange(
'rankings',
(page - 1) * 10,
page * 10 - 1,
0,
-1,
);

console.log('userranking', userRanking); // ok

const foundUsers = await this.userRepository.findRanksInfos(
userRanking,
);
Expand All @@ -37,7 +34,7 @@ export class RanksService {

const rankUsers: RankUserReturnDto[] = foundUsers.map((user, index) => ({
...user,
ranking: index + 1 + (page - 1) * 10,
ranking: index + 1
}));
const totalItemCount = await this.userRepository.count(); // TODO: redis에 저장된 총 유저 수를 가져와야 하지 않을까?

Expand Down
40 changes: 24 additions & 16 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';

@Controller('users')
@ApiTags('users')
@UseGuards(JwtAuthGuard)
export class UsersController {
constructor(
private readonly usersService: UsersService,
Expand All @@ -35,7 +34,8 @@ export class UsersController {
) {}

private readonly logger = new Logger(UsersController.name);


@UseGuards(JwtAuthGuard)
@Post('/friends')
@ApiOperation({
summary: '친구추가',
Expand All @@ -49,7 +49,8 @@ export class UsersController {
await this.friendsService.createFriend(user.id, toUserId);
// TODO: 친구요청을 받은 유저에게 알림 보내기
}


@UseGuards(JwtAuthGuard)
@Delete('/friends')
@ApiOperation({
summary: '친구삭제',
Expand All @@ -62,7 +63,8 @@ export class UsersController {
) {
await this.friendsService.deleteFriend(user.id, toUserId);
}


@UseGuards(JwtAuthGuard)
@Get('/friends')
@ApiOperation({
summary: '친구목록 조회',
Expand All @@ -79,7 +81,8 @@ export class UsersController {

return friendResponseDto;
}


@UseGuards(JwtAuthGuard)
@Get('/me')
@ApiOperation({
summary: '내 정보 조회',
Expand All @@ -90,7 +93,8 @@ export class UsersController {

return myProfile;
}


@UseGuards(JwtAuthGuard)
@Get('/profile/:nickname')
@ApiOperation({
summary: '유저 정보 조회',
Expand All @@ -108,7 +112,8 @@ export class UsersController {

return userProfile;
}


@UseGuards(JwtAuthGuard)
@Get('/games/:nickname')
@ApiOperation({
summary: '게임 정보 조회',
Expand All @@ -128,7 +133,8 @@ export class UsersController {

return gameHistories;
}


@UseGuards(JwtAuthGuard)
@Post('/blocks')
@ApiOperation({
summary: '유저 차단',
Expand All @@ -142,7 +148,8 @@ export class UsersController {
) {
await this.blocksService.applyBlock(user.id, toUserId);
}


@UseGuards(JwtAuthGuard)
@Delete('/blocks')
@ApiOperation({
summary: '유저 차단 해제',
Expand All @@ -156,6 +163,7 @@ export class UsersController {
await this.blocksService.cancelBlock(user.id, toUserId);
}

@UseGuards(JwtAuthGuard)
@Get('/blocks')
@ApiOperation({
summary: '유저 차단목록 조회',
Expand All @@ -171,20 +179,19 @@ export class UsersController {

return BlockUserResponseDto;
}

@Get('/rank')
@ApiOperation({
summary: '랭킹 조회',
description: '레디스로부터 pagination해 랭킹 목록을 제공합니다.',
})
async paging(@Query('page', ParseIntPipe, PositiveIntPipe) page: number) {
const rankResponseDto = await this.ranksServices.findRanksWithPage(
page,
);
async paging() {
const rankResponseDto = await this.ranksServices.findRanksWithPage();

return rankResponseDto;
}


@UseGuards(JwtAuthGuard)
@Patch('/me/statusMessage')
@ApiOperation({
summary: '상태 메세지 변경',
Expand All @@ -211,7 +218,8 @@ export class UsersController {

await this.usersService.updateMyStatusMessage(user.id, statusMessage);
}


@UseGuards(JwtAuthGuard)
@Patch('/me/avatar')
@ApiOperation({
summary: '아바타 변경',
Expand Down

0 comments on commit 580c439

Please sign in to comment.