Skip to content

Commit

Permalink
✨ Access_Code를 이용하여 그룹에 대한 정보 반환 API 구현
Browse files Browse the repository at this point in the history
승인 코드를 사용하여 그룹 정보를 반환하는 API를 구현합니다.
  • Loading branch information
ldhbenecia committed Feb 2, 2024
1 parent 1f7030e commit 84bf986
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/backend/src/groups/groups.controller.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Group & { membersCount: number }> {
return this.groupsService.getGroupByAccessCode(accessCode);
}

@Get('/:id')
@ApiOperation({
summary: '특정 그룹 정보 조회',
Expand Down
21 changes: 21 additions & 0 deletions app/backend/src/groups/groups.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ export class GroupsRepository {
return Promise.all(groupPromises);
}

async getGroupByAccessCode(accessCode: string): Promise<Group & { membersCount: number }> {
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<Group & { membersCount: number }> {
const group = await this.prisma.group.findUnique({
where: {
Expand Down
4 changes: 4 additions & 0 deletions app/backend/src/groups/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class GroupsService {
return this.groupsRepository.getAllGroups();
}

async getGroupByAccessCode(accessCode: string): Promise<Group & { membersCount: number }> {
return this.groupsRepository.getGroupByAccessCode(accessCode);
}

async getGroups(id: number): Promise<Group & { membersCount: number }> {
return this.groupsRepository.getGroups(id);
}
Expand Down

0 comments on commit 84bf986

Please sign in to comment.