Skip to content

Commit

Permalink
q
Browse files Browse the repository at this point in the history
  • Loading branch information
overthestream committed Dec 19, 2023
1 parent d9c62ca commit 7c453e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
8 changes: 2 additions & 6 deletions src/blurting/blurting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { JwtPayload } from 'src/interfaces/auth';
import { UserService } from 'src/user/user.service';
import { AnswerDto, BlurtingPageDto } from 'src/dtos/blurtingPage.dto';
import {
ApiBadRequestResponse,
ApiConflictResponse,
ApiCreatedResponse,
ApiHeader,
ApiBody,
Expand Down Expand Up @@ -120,15 +118,13 @@ export class BlurtingController {

@UseGuards(AuthGuard('access'))
@Post('/register')
@ApiBadRequestResponse({ description: '이미 큐에 있음' })
@ApiConflictResponse({ description: '이미 블러팅 그룹이 있음' })
@ApiCreatedResponse({
description: '큐에 등록 시 false, 그룹이 만들어졌을 시 true',
description: '큐에 등록시 0 , 그룹이 있으면 1, 매칭 중이면 2',
})
async registerGroupQueue(@Req() req: Request) {
const { id } = req.user as JwtPayload;

await this.blurtingService.registerGroupQueue(id);
return await this.blurtingService.registerGroupQueue(id);
}

@UseGuards(AuthGuard('access'))
Expand Down
17 changes: 7 additions & 10 deletions src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import {
BadRequestException,
ConflictException,
Inject,
Injectable,
NotFoundException,
Expand Down Expand Up @@ -248,32 +247,30 @@ export class BlurtingService {
async registerGroupQueue(id: number) {
const user = await this.userService.findUserByVal('id', id);
if (user.group) {
throw new ConflictException('이미 그룹이 있습니다.');
return 1;
}
const sexOrient = this.getUserSexOrient(user.userInfo);

const groupQueue: number[] = await this.cacheManager.get(sexOrient);
if (groupQueue.includes(id)) {
throw new BadRequestException(
'이미 블러팅 매치메이킹 큐에 등록되어 있습니다.',
);
return 2;
}
if (groupQueue.length < 2) {
groupQueue.push(id);
await this.cacheManager.set(sexOrient, groupQueue);
return false;
return 0;
}
if (sexOrient.endsWith('homo')) {
if (groupQueue.length >= 5) {
const groupIds = groupQueue.slice(0, 5);
groupIds.push(id);
await this.createGroup(groupIds);
await this.cacheManager.set(sexOrient, groupQueue.slice(5));
return true;
return 1;
} else {
groupQueue.push(id);
await this.cacheManager.set(sexOrient, groupQueue);
return false;
return 0;
}
}
const oppositeQueueName = this.getOppositeQueueName(sexOrient);
Expand All @@ -289,11 +286,11 @@ export class BlurtingService {
const groupIds = firstGroupIds.concat(secondGroupIds);

await this.createGroup(groupIds);
return true;
return 1;
} else {
groupQueue.push(id);
await this.cacheManager.set(sexOrient, groupQueue);
return false;
return 0;
}
}

Expand Down

0 comments on commit 7c453e6

Please sign in to comment.