import { Body, Controller, Get, Param, Patch, Post } from "@nestjs/common"; import { CreateGroupDto } from "../dto/create-group.dto"; import { GroupsService } from "../application/groups.service"; import { RenameGroupDto } from "../dto/rename-group.dto"; import { IncomingEventDto } from "src/model/dto/incoming-event.dto"; import { ulid } from 'ulid'; @Controller({path: 'groups'}) export class GroupsController { constructor(private groupsService: GroupsService) {} @Get() getGroups() { return this.groupsService.getAll(); } @Post() createGroup(@Body() dto: CreateGroupDto) { return this.groupsService.create(dto); } @Patch(':id/name') rename(@Param('id') id: string, @Body() dto: RenameGroupDto) { // actorId später z.B. aus Header/Cookie ziehen const event: IncomingEventDto = { id: ulid(), payload: { to: dto.name }, type: 'GROUP_RENAMED', actorId: undefined } return this.ingest(id, [event]) } @Post(':groupId/events/batch') ingest( @Param('groupId') groupId: string, @Body() events: IncomingEventDto[], ) { return this.groupsService.ingestEvents(groupId, events); } }