feat: scaffold center and guild backend NestJS skeletons

This commit is contained in:
nav
2026-05-12 08:31:43 +00:00
parent 026be99393
commit 88bec71cf8
26 changed files with 3597 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
type Message = {
messageId: string;
seq: number;
content: string;
};
@Controller('channels/:id/messages')
export class MessagingController {
private seqByChannel = new Map<string, number>();
private messagesByChannel = new Map<string, Message[]>();
@Post()
create(@Param('id') channelId: string, @Body() body: { content?: string; messageId?: string }) {
const next = (this.seqByChannel.get(channelId) ?? 0) + 1;
this.seqByChannel.set(channelId, next);
const message: Message = {
messageId: body.messageId ?? `m-${channelId}-${next}`,
seq: next,
content: body.content ?? '',
};
const arr = this.messagesByChannel.get(channelId) ?? [];
arr.push(message);
this.messagesByChannel.set(channelId, arr);
return message;
}
@Patch(':messageId')
edit(@Param('id') channelId: string, @Param('messageId') messageId: string, @Body() body: { content?: string }) {
const arr = this.messagesByChannel.get(channelId) ?? [];
const item = arr.find((m) => m.messageId === messageId);
if (!item) return { status: 'not_found' };
item.content = body.content ?? item.content;
return item;
}
@Delete(':messageId')
remove(@Param('id') channelId: string, @Param('messageId') messageId: string) {
const arr = this.messagesByChannel.get(channelId) ?? [];
const next = arr.filter((m) => m.messageId !== messageId);
this.messagesByChannel.set(channelId, next);
return { status: 'deleted', messageId };
}
@Get()
listBySeq(
@Param('id') channelId: string,
@Query('seq_from') seqFrom?: string,
@Query('seq_to') seqTo?: string,
) {
const from = seqFrom ? Number(seqFrom) : 1;
const to = seqTo ? Number(seqTo) : Number.MAX_SAFE_INTEGER;
const arr = this.messagesByChannel.get(channelId) ?? [];
return {
items: arr.filter((m) => m.seq >= from && m.seq <= to),
};
}
}