From e8ecce71b12c5b054f9bb1a26a3bacd37c3a4c9d Mon Sep 17 00:00:00 2001 From: Cagatay Uslu Date: Wed, 28 May 2025 14:22:20 +0200 Subject: [PATCH] feat: add missing endpoints and enhance group functionality --- src/group/group.controller.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/group/group.controller.ts b/src/group/group.controller.ts index 4941808..ef72484 100644 --- a/src/group/group.controller.ts +++ b/src/group/group.controller.ts @@ -43,13 +43,40 @@ export class GroupController { @HttpCode(HttpStatus.OK) async join(@Param('id') groupId: string, @Body('userId') userId: string) { await this.groupService.joinGroup(groupId, userId); - // success + const group = await this.groupService.findOne(groupId); return { message: `User with ID ${userId} has successfully joined the group with ID ${groupId}`, + invite_code: group.invite_code, }; } - // TODO #98: Add missing endpoints + @Post(':id/leave') + @HttpCode(HttpStatus.OK) + async leave(@Param('id') groupId: string, @Body('userId') userId: string) { + await this.groupService.leaveGroup(groupId, userId); + return { + message: `User with ID ${userId} has successfully left the group with ID ${groupId}`, + }; + } + + @Get(':id/members') + async getMembers(@Param('id') groupId: string) { + const group = await this.groupService.findOne(groupId); + return group.members; + } + + @Get(':id/group-info') + async getGroupInfo(@Param('id') groupId: string) { + const group = await this.groupService.findOne(groupId); + return { + id: group.group_id, + name: group.group_name, + invite_code: group.invite_code, + members: group.members, + messages: group.messages, + challenges: group.challenges, + }; + } @Put(':id') update(@Param('id') id: string, @Body() updateGroupDto: UpdateGroupDto) {