From ec1590e86bef22228ef770f28ecebc70fd8cf317 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Sun, 28 Jan 2024 13:42:07 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=ED=8A=B9=EC=A0=95=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=20=EC=A0=95=EB=B3=B4=20=EB=B0=98=ED=99=98=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 특정 그룹의 id, 이름, 가입 멤버 수를 반환합니다. --- app/backend/src/groups/groups.controller.ts | 18 +++++++++++++++--- app/backend/src/groups/groups.repository.ts | 15 +++++++++++++++ app/backend/src/groups/groups.service.ts | 4 ++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/backend/src/groups/groups.controller.ts b/app/backend/src/groups/groups.controller.ts index 2a5284635..fe1bbfc48 100644 --- a/app/backend/src/groups/groups.controller.ts +++ b/app/backend/src/groups/groups.controller.ts @@ -26,7 +26,19 @@ export class GroupsController { return this.groupsService.getAllGroups(); } - @Get('/:id/groups') + @Get('/:id') + @ApiOperation({ + summary: '특정 그룹 정보 조회', + description: '특정 그룹의 정보를 조회합니다.', + }) + @ApiResponse({ status: 200, description: 'Successfully retrieved', type: [GroupsWithMemberCountDto] }) + @ApiResponse({ status: 401, description: 'Unauthorized' }) + @ApiResponse({ status: 404, description: 'Group with id not found' }) + async getGroups(@Param('id', ParseIntPipe) id: number): Promise { + return this.groupsService.getGroups(id); + } + + @Get('/:id/members') @ApiOperation({ summary: '특정 그룹 소속 인원 조회', description: '특정 그룹의 Id 값으로 해당 그룹의 소속 인원을 조회합니다.', @@ -40,8 +52,8 @@ export class GroupsController { @Post('/') @ApiOperation({ - summary: '그룹 개설', - description: '새로운 모각코를 개설합니다.', + summary: '그룹 생성', + description: '새로운 그룹을 생성합니다.', }) @ApiBody({ type: CreateGroupsDto }) @ApiResponse({ status: 201, description: 'Successfully created', type: CreateGroupsDto }) diff --git a/app/backend/src/groups/groups.repository.ts b/app/backend/src/groups/groups.repository.ts index cad32d2b8..9740e59c7 100644 --- a/app/backend/src/groups/groups.repository.ts +++ b/app/backend/src/groups/groups.repository.ts @@ -27,6 +27,21 @@ export class GroupsRepository { return Promise.all(groupPromises); } + async getGroups(id: number): Promise { + const group = await this.prisma.group.findUnique({ + where: { + id: id, + }, + }); + + if (!group) { + throw new NotFoundException(`Group with ID ${id} not found.`); + } + + const membersCount = await this.getGroupMembersCount(id); + return { ...group, membersCount }; + } + async getAllMembersOfGroup(groupId: number): Promise { const groupToUsers = await this.prisma.groupToUser.findMany({ where: { diff --git a/app/backend/src/groups/groups.service.ts b/app/backend/src/groups/groups.service.ts index 1af741c20..deb41ae17 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 getGroups(id: number): Promise { + return this.groupsRepository.getGroups(id); + } + async getAllMembersOfGroup(id: number): Promise { return this.groupsRepository.getAllMembersOfGroup(id); }