diff --git a/app/backend/src/groups/groups.controller.ts b/app/backend/src/groups/groups.controller.ts index c634c52c..a4e31dd1 100644 --- a/app/backend/src/groups/groups.controller.ts +++ b/app/backend/src/groups/groups.controller.ts @@ -1,5 +1,5 @@ -import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, UseGuards } from '@nestjs/common'; -import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Query, UseGuards } from '@nestjs/common'; +import { ApiBody, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'; import { GroupsService } from './groups.service'; import { GetUser } from 'libs/decorators/get-user.decorator'; import { AtGuard } from 'src/auth/guards/at.guard'; @@ -26,6 +26,20 @@ export class GroupsController { return this.groupsService.getAllGroups(); } + @Get('/info') + @ApiOperation({ + summary: '승인코드를 사용하여 그룹 정보 추출', + description: '승인 코드를 사용하여 특정 그룹 정보를 추출합니다.', + }) + @ApiQuery({ name: 'access-code', description: '참가할 그룹의 승인 코드' }) + @ApiResponse({ status: 201, description: 'Successfully retrieved group information' }) + @ApiResponse({ status: 401, description: 'Unauthorized' }) + @ApiResponse({ status: 403, description: 'Forbidden' }) + @ApiResponse({ status: 404, description: 'Group not found for the provided access code' }) + async getGroupByAccessCode(@Query('access_code') accessCode: string): Promise { + return this.groupsService.getGroupByAccessCode(accessCode); + } + @Get('/:id') @ApiOperation({ summary: '특정 그룹 정보 조회', diff --git a/app/backend/src/groups/groups.repository.ts b/app/backend/src/groups/groups.repository.ts index fd367675..62e9ee64 100644 --- a/app/backend/src/groups/groups.repository.ts +++ b/app/backend/src/groups/groups.repository.ts @@ -28,6 +28,27 @@ export class GroupsRepository { return Promise.all(groupPromises); } + async getGroupByAccessCode(accessCode: string): Promise { + const groupAccessCode = await this.prisma.groupAccessCode.findUnique({ + where: { + accessCode: accessCode, + }, + include: { + groupAccessCodes: true, + }, + }); + + if (!groupAccessCode) { + throw new NotFoundException('Group not found for the provided access code'); + } + + const membersCount = await this.getGroupMembersCount(Number(groupAccessCode.groupId)); + return { + ...groupAccessCode.groupAccessCodes, + membersCount, + }; + } + async getGroups(id: number): Promise { const group = await this.prisma.group.findUnique({ where: { diff --git a/app/backend/src/groups/groups.service.ts b/app/backend/src/groups/groups.service.ts index afad0032..b98fce7c 100644 --- a/app/backend/src/groups/groups.service.ts +++ b/app/backend/src/groups/groups.service.ts @@ -12,6 +12,10 @@ export class GroupsService { return this.groupsRepository.getAllGroups(); } + async getGroupByAccessCode(accessCode: string): Promise { + return this.groupsRepository.getGroupByAccessCode(accessCode); + } + async getGroups(id: number): Promise { return this.groupsRepository.getGroups(id); }