Files
course-craft-service/apps/api/src/groups/groups.controller.ts
2026-02-06 14:53:52 +00:00

53 lines
2.1 KiB
TypeScript

import { Controller, Post, Get, Param, Body } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { GroupsService } from './groups.service';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { User } from '@coursecraft/database';
@ApiTags('groups')
@Controller('groups')
@ApiBearerAuth()
export class GroupsController {
constructor(private groupsService: GroupsService) {}
@Post()
async createGroup(@Body() body: { courseId: string; name: string; description?: string }, @CurrentUser() user: User): Promise<any> {
return this.groupsService.createGroup(body.courseId, user.id, body.name, body.description);
}
@Post(':groupId/members')
async addMember(@Param('groupId') groupId: string, @Body('userId') userId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.addMember(groupId, user.id, userId);
}
@Get('course/:courseId/default')
async getDefaultGroup(@Param('courseId') courseId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.getDefaultGroup(courseId, user.id);
}
@Get(':groupId/members')
async getMembers(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.getGroupMembers(groupId, user.id);
}
@Get(':groupId/messages')
async getMessages(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.getGroupMessages(groupId, user.id);
}
@Post(':groupId/messages')
async sendMessage(@Param('groupId') groupId: string, @Body('content') content: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.sendMessage(groupId, user.id, content);
}
@Post(':groupId/invite-link')
async createInviteLink(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.createInviteLink(groupId, user.id);
}
@Post('join/:groupId')
async joinByInvite(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
return this.groupsService.joinByInvite(groupId, user.id);
}
}