diff --git a/app/backend/src/mogaco/mogaco.controller.ts b/app/backend/src/mogaco/mogaco.controller.ts index f744b1b49..0b9711080 100644 --- a/app/backend/src/mogaco/mogaco.controller.ts +++ b/app/backend/src/mogaco/mogaco.controller.ts @@ -103,4 +103,17 @@ export class MogacoController { async getParticipants(@Param('id', ParseIntPipe) id: number): Promise { return this.mogacoService.getParticipants(id); } + + @Delete('/:id/join') + @ApiOperation({ + summary: '모각코 참가 취소', + description: '특정 모각코 참가를 취소합니다.', + }) + @ApiParam({ name: 'id', description: '참가를 취소할 모각코의 Id' }) + @ApiResponse({ status: 200, description: 'Successfully cancelled join' }) + @ApiResponse({ status: 401, description: 'Unauthorized' }) + @ApiResponse({ status: 403, description: 'Forbidden' }) + async cancelMogacoJoin(@Param('id', ParseIntPipe) id: number, @GetUser() member: Member): Promise { + return this.mogacoService.cancelMogacoJoin(id, member); + } } diff --git a/app/backend/src/mogaco/mogaco.repository.ts b/app/backend/src/mogaco/mogaco.repository.ts index f8ebc9a3a..cec637f6b 100644 --- a/app/backend/src/mogaco/mogaco.repository.ts +++ b/app/backend/src/mogaco/mogaco.repository.ts @@ -145,4 +145,43 @@ export class MogacoRepository { // 가져온 참가자 목록의 각 참가자의 member 속성을 통해 실제 멤버 객체로 매핑하여 반환 return participants.map((participant) => participant.member); } + + async cancelMogacoJoin(id: number, member: Member): Promise { + const mogaco = await this.prisma.mogaco.findUnique({ + where: { id, deletedAt: null }, + include: { + member: true, + }, + }); + + if (!mogaco) { + throw new NotFoundException(`Mogaco with id ${id} not found`); + } + + const participant = await this.prisma.participant.findUnique({ + where: { + postId_userId: { + postId: mogaco.id, + userId: member.id, + }, + }, + }); + + if (!participant) { + throw new NotFoundException(`Member with id ${member.id} is not participating in Mogaco with id ${id}`); + } + + if (mogaco.memberId !== member.id) { + throw new ForbiddenException(`You do not have permission to cancel participation in this Mogaco`); + } + + await this.prisma.participant.delete({ + where: { + postId_userId: { + postId: mogaco.id, + userId: member.id, + }, + }, + }); + } } diff --git a/app/backend/src/mogaco/mogaco.service.ts b/app/backend/src/mogaco/mogaco.service.ts index 736e4373b..5eee53049 100644 --- a/app/backend/src/mogaco/mogaco.service.ts +++ b/app/backend/src/mogaco/mogaco.service.ts @@ -37,4 +37,8 @@ export class MogacoService { async getParticipants(id: number): Promise { return this.mogacoRepository.getParticipants(id); } + + async cancelMogacoJoin(id: number, member: Member): Promise { + return this.mogacoRepository.cancelMogacoJoin(id, member); + } }