Skip to content

Commit

Permalink
Merge pull request #511 from ldhbenecia/feature/groups
Browse files Browse the repository at this point in the history
[Feat] 특정 그룹 정보 반환 API 구현
  • Loading branch information
ldhbenecia authored Jan 28, 2024
2 parents 721c8b0 + ec1590e commit f6a8922
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/backend/src/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group & { membersCount: number }> {
return this.groupsService.getGroups(id);
}

@Get('/:id/members')
@ApiOperation({
summary: '특정 그룹 소속 인원 조회',
description: '특정 그룹의 Id 값으로 해당 그룹의 소속 인원을 조회합니다.',
Expand All @@ -40,8 +52,8 @@ export class GroupsController {

@Post('/')
@ApiOperation({
summary: '그룹 개설',
description: '새로운 모각코를 개설합니다.',
summary: '그룹 생성',
description: '새로운 그룹을 생성합니다.',
})
@ApiBody({ type: CreateGroupsDto })
@ApiResponse({ status: 201, description: 'Successfully created', type: CreateGroupsDto })
Expand Down
15 changes: 15 additions & 0 deletions app/backend/src/groups/groups.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ export class GroupsRepository {
return Promise.all(groupPromises);
}

async getGroups(id: number): Promise<Group & { membersCount: number }> {
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<MemberInformationDto[]> {
const groupToUsers = await this.prisma.groupToUser.findMany({
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 getGroups(id: number): Promise<Group & { membersCount: number }> {
return this.groupsRepository.getGroups(id);
}

async getAllMembersOfGroup(id: number): Promise<MemberInformationDto[]> {
return this.groupsRepository.getAllMembersOfGroup(id);
}
Expand Down

0 comments on commit f6a8922

Please sign in to comment.