Skip to content

Commit

Permalink
✨ 모각코 참가 취소 구현 및 Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhbenecia committed Nov 22, 2023
1 parent 544c853 commit 340402e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/backend/src/mogaco/mogaco.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ export class MogacoController {
async getParticipants(@Param('id', ParseIntPipe) id: number): Promise<Member[]> {
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<void> {
return this.mogacoService.cancelMogacoJoin(id, member);
}
}
39 changes: 39 additions & 0 deletions app/backend/src/mogaco/mogaco.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,43 @@ export class MogacoRepository {
// 가져온 참가자 목록의 각 참가자의 member 속성을 통해 실제 멤버 객체로 매핑하여 반환
return participants.map((participant) => participant.member);
}

async cancelMogacoJoin(id: number, member: Member): Promise<void> {
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,
},
},
});
}
}
4 changes: 4 additions & 0 deletions app/backend/src/mogaco/mogaco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export class MogacoService {
async getParticipants(id: number): Promise<Member[]> {
return this.mogacoRepository.getParticipants(id);
}

async cancelMogacoJoin(id: number, member: Member): Promise<void> {
return this.mogacoRepository.cancelMogacoJoin(id, member);
}
}

0 comments on commit 340402e

Please sign in to comment.