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