[+] Completed lab 2
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Controller, Get, Path, Post, Request, Route, SuccessResponse, Tags } from 'tsoa';
|
||||
import type { Message, Page } from '../domain/models';
|
||||
import type { SessionRequest } from '../middleware/auth';
|
||||
import { createMessage, listMessages } from '../services/message.service';
|
||||
|
||||
@Route('api/v1/chats/{chat_id}/messages')
|
||||
@Tags('Messages')
|
||||
export class MessagesController extends Controller {
|
||||
@Post()
|
||||
@SuccessResponse(201, 'Created')
|
||||
public async createMessage(@Path() chat_id: string, @Request() req: SessionRequest): Promise<Message> {
|
||||
this.setStatus(201);
|
||||
return createMessage(req.session.user, chat_id, req.body);
|
||||
}
|
||||
|
||||
@Get()
|
||||
public async listMessages(@Path() chat_id: string, @Request() req: SessionRequest): Promise<Page<Message>> {
|
||||
return listMessages(req.session.user, chat_id, req.query.limit, req.query.cursor);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user