From 1f7030eeb11cd81fd7200dc566a9701745a49491 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Thu, 1 Feb 2024 16:32:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20=EA=B7=B8=EB=A3=B9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20GroupAccessCode=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20DB=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/groups/groups.repository.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/backend/src/groups/groups.repository.ts b/app/backend/src/groups/groups.repository.ts index b5c92cec..fd367675 100644 --- a/app/backend/src/groups/groups.repository.ts +++ b/app/backend/src/groups/groups.repository.ts @@ -3,6 +3,7 @@ import { PrismaService } from 'prisma/prisma.service'; import { Group, Member } from '@prisma/client'; import { MemberInformationDto } from 'src/member/dto/member.dto'; import { CreateGroupsDto } from './dto/create-groups.dto'; +import { v4 as uuidv4 } from 'uuid'; @Injectable() export class GroupsRepository { @@ -74,6 +75,14 @@ export class GroupsRepository { }, }); + const accessCode = uuidv4(); + await this.prisma.groupAccessCode.create({ + data: { + accessCode, + groupId: group.id, + }, + }); + return group; } catch (error) { throw new Error(`Failed to create group: ${error.message}`); From 84bf986d3437c96973c4bff4af194d967a1dd3e3 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Fri, 2 Feb 2024 16:21:43 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20Access=5FCode=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=A0=95=EB=B3=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 승인 코드를 사용하여 그룹 정보를 반환하는 API를 구현합니다. --- app/backend/src/groups/groups.controller.ts | 18 ++++++++++++++++-- app/backend/src/groups/groups.repository.ts | 21 +++++++++++++++++++++ app/backend/src/groups/groups.service.ts | 4 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) 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); } From 95264d6846103f48af199cd8f1e61f5e3f5c051e Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Fri, 2 Feb 2024 16:42:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20=EA=B7=B8=EB=A3=B9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EC=8A=B9=EC=9D=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/groups/groups.controller.ts | 5 ++++- app/backend/src/groups/groups.repository.ts | 6 ++++-- app/backend/src/groups/groups.service.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/backend/src/groups/groups.controller.ts b/app/backend/src/groups/groups.controller.ts index a4e31dd1..e08a9a38 100644 --- a/app/backend/src/groups/groups.controller.ts +++ b/app/backend/src/groups/groups.controller.ts @@ -72,7 +72,10 @@ export class GroupsController { @ApiBody({ type: CreateGroupsDto }) @ApiResponse({ status: 201, description: 'Successfully created', type: CreateGroupsDto }) @ApiResponse({ status: 401, description: 'Unauthorized' }) - async createGroups(@Body() createGroupsDto: CreateGroupsDto, @GetUser() member: Member): Promise { + async createGroups( + @Body() createGroupsDto: CreateGroupsDto, + @GetUser() member: Member, + ): Promise<{ group: Group; accessCode: string }> { return this.groupsService.createGroups(createGroupsDto, member); } diff --git a/app/backend/src/groups/groups.repository.ts b/app/backend/src/groups/groups.repository.ts index 62e9ee64..e544401f 100644 --- a/app/backend/src/groups/groups.repository.ts +++ b/app/backend/src/groups/groups.repository.ts @@ -82,7 +82,7 @@ export class GroupsRepository { })); } - async createGroups(createGroupsDto: CreateGroupsDto, member: Member): Promise { + async createGroups(createGroupsDto: CreateGroupsDto, member: Member): Promise<{ group: Group; accessCode: string }> { try { const { title, groupTypeId } = createGroupsDto; @@ -104,7 +104,9 @@ export class GroupsRepository { }, }); - return group; + await this.joinGroup(Number(group.id), member); + + return { group, accessCode }; } catch (error) { throw new Error(`Failed to create group: ${error.message}`); } diff --git a/app/backend/src/groups/groups.service.ts b/app/backend/src/groups/groups.service.ts index b98fce7c..33b3d2d5 100644 --- a/app/backend/src/groups/groups.service.ts +++ b/app/backend/src/groups/groups.service.ts @@ -24,7 +24,7 @@ export class GroupsService { return this.groupsRepository.getAllMembersOfGroup(id); } - async createGroups(createGroupsDto: CreateGroupsDto, member: Member): Promise { + async createGroups(createGroupsDto: CreateGroupsDto, member: Member): Promise<{ group: Group; accessCode: string }> { return this.groupsRepository.createGroups(createGroupsDto, member); } From fc1b1b9d2a1d7c2d80cbfe565780f91b101c706d Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Fri, 2 Feb 2024 16:49:01 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Groups=20API=20Swagger?= =?UTF-8?q?=20Response=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/groups/groups.controller.ts | 2 - app/backend/src/groups/groups.repository.ts | 42 ++++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/app/backend/src/groups/groups.controller.ts b/app/backend/src/groups/groups.controller.ts index e08a9a38..693a2548 100644 --- a/app/backend/src/groups/groups.controller.ts +++ b/app/backend/src/groups/groups.controller.ts @@ -34,7 +34,6 @@ export class GroupsController { @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); @@ -101,7 +100,6 @@ export class GroupsController { @ApiParam({ name: 'id', description: '참가를 취소할 그룹의 Id' }) @ApiResponse({ status: 200, description: 'Successfully leaved join' }) @ApiResponse({ status: 401, description: 'Unauthorized' }) - @ApiResponse({ status: 403, description: 'Forbidden' }) @ApiResponse({ status: 404, description: 'Group with id not found' }) async leaveGroup(@Param('id', ParseIntPipe) id: number, @GetUser() member: Member): Promise { return this.groupsService.leaveGroup(id, member); diff --git a/app/backend/src/groups/groups.repository.ts b/app/backend/src/groups/groups.repository.ts index e544401f..511b1fd9 100644 --- a/app/backend/src/groups/groups.repository.ts +++ b/app/backend/src/groups/groups.repository.ts @@ -83,33 +83,29 @@ export class GroupsRepository { } async createGroups(createGroupsDto: CreateGroupsDto, member: Member): Promise<{ group: Group; accessCode: string }> { - try { - const { title, groupTypeId } = createGroupsDto; - - const group = await this.prisma.group.create({ - data: { - title: title, - groupTypeId: groupTypeId, - member: { - connect: { id: Number(member.id) }, - }, - }, - }); + const { title, groupTypeId } = createGroupsDto; - const accessCode = uuidv4(); - await this.prisma.groupAccessCode.create({ - data: { - accessCode, - groupId: group.id, + const group = await this.prisma.group.create({ + data: { + title: title, + groupTypeId: groupTypeId, + member: { + connect: { id: Number(member.id) }, }, - }); + }, + }); - await this.joinGroup(Number(group.id), member); + const accessCode = uuidv4(); + await this.prisma.groupAccessCode.create({ + data: { + accessCode, + groupId: group.id, + }, + }); - return { group, accessCode }; - } catch (error) { - throw new Error(`Failed to create group: ${error.message}`); - } + await this.joinGroup(Number(group.id), member); + + return { group, accessCode }; } async joinGroup(id: number, member: Member): Promise {