chore: migrate minimum from lab1

This commit is contained in:
2026-10-21 09:41:45 +03:00
parent 65003b6119
commit d8fb486709
44 changed files with 11664 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import {
Body,
Controller,
Get,
HttpCode,
Param,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '../common/auth/auth.guard';
import { CurrentUser } from '../common/auth/current-user.decorator';
import { parseLimit, rawCursorParam } from '../common/dto/pagination-query.dto';
import { User } from '../common/store/domain';
import { CreateMessageDto } from './dto/create-message.dto';
import {
MessagePageResponse,
MessageResponse,
toMessageResponse,
} from './dto/message.response';
import { MessagesService } from './messages.service';
@Controller('api/v1/chats/:chatId/messages')
@UseGuards(AuthGuard)
export class MessagesController {
constructor(private readonly messages: MessagesService) {}
@Post()
@HttpCode(201)
create(
@Param('chatId') chatId: string,
@Body() dto: CreateMessageDto,
@CurrentUser() user: User,
): MessageResponse {
const message = this.messages.create(chatId, user.id, dto.text);
return toMessageResponse(message);
}
@Get()
list(
@Param('chatId') chatId: string,
@CurrentUser() user: User,
@Query('limit') limitRaw: unknown,
@Query('cursor') cursorRaw: unknown,
): MessagePageResponse {
const limit = parseLimit(limitRaw);
const cursor = rawCursorParam(cursorRaw);
return this.messages.list(chatId, user.id, limit, cursor);
}
}