manicanldes-backend/src/forum/forum.controller.ts

47 lines
1.3 KiB
TypeScript

import {
Body,
Controller,
Get,
Param,
ParseUUIDPipe,
Post,
Query,
} from '@nestjs/common';
import { CurrentPrincipal } from '../identity/access.decorator';
import type { Principal } from '../identity/identity.types';
import { pageSchema, type PageInput } from '../identity/identity.schemas';
import { SchemaPipe } from '../common/validation.pipe';
import {
forumThreadSchema,
forumReplySchema,
type ForumThreadInput,
type ForumReplyInput,
} from './forum.schemas';
import { ForumSubmissionStore } from './forum-submission.store';
@Controller('forum')
export class ForumController {
constructor(private readonly posts: ForumSubmissionStore) {}
@Get('posts')
own(
@CurrentPrincipal() actor: Principal,
@Query(new SchemaPipe(pageSchema)) page: PageInput,
) {
return this.posts.own(actor, page);
}
@Post('threads')
submit(
@CurrentPrincipal() actor: Principal,
@Body(new SchemaPipe(forumThreadSchema)) input: ForumThreadInput,
) {
return this.posts.submit(actor, input);
}
@Post('threads/:id/replies')
reply(
@CurrentPrincipal() actor: Principal,
@Param('id', ParseUUIDPipe) id: string,
@Body(new SchemaPipe(forumReplySchema)) input: ForumReplyInput,
) {
return this.posts.submit(actor, input, id);
}
}