Skip to content

Commit

Permalink
✨ 그룹 삭제 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhbenecia committed Mar 9, 2024
1 parent a1875ba commit 96f2381
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/backend/src/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ export class GroupsController {
return this.groupsService.approveGroup(id, memberId, member);
}

@Delete('/:id')
@ApiOperation({
summary: '그룹 삭제',
description: '특정 그룹을 삭제합니다.',
})
@ApiParam({ name: 'id', description: '삭제할 그룹의 Id' })
@ApiResponse({ status: 200, description: 'Successfully deleted the group' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
@ApiResponse({ status: 403, description: 'Forbidden' })
@ApiResponse({ status: 404, description: 'Group with id not found' })
async deleteGroup(@Param('id', ParseIntPipe) id: number, @GetUser() member: Member): Promise<void> {
await this.groupsService.deleteGroup(id, member);
}

@Delete('/:id/leave')
@ApiOperation({
summary: '그룹 참가 취소',
Expand Down
26 changes: 26 additions & 0 deletions app/backend/src/groups/groups.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ export class GroupsRepository {
});
}

async deleteGroup(groupId: number, member: Member): Promise<void> {
const group = await this.prisma.group.findUnique({
where: {
id: groupId,
},
});

if (!group) {
throw new NotFoundException(`Group with id ${groupId} not found`);
}

const isGroupOwner = await this.isGroupOwner(groupId, Number(member.id));
if (!isGroupOwner) {
throw new ForbiddenException('Only group owners can delete the group');
}

await this.prisma.group.update({
where: {
id: groupId,
},
data: {
deletedAt: new Date(),
},
});
}

async leaveGroup(groupId: number, member: Member): Promise<void> {
const group = await this.prisma.group.findUnique({
where: { id: groupId },
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 @@ -47,6 +47,10 @@ export class GroupsService {
}
}

async deleteGroup(groupId: number, member: Member): Promise<void> {
await this.groupsRepository.deleteGroup(groupId, member);
}

async leaveGroup(id: number, member: Member): Promise<void> {
await this.groupsRepository.leaveGroup(id, member);
}
Expand Down

0 comments on commit 96f2381

Please sign in to comment.