prepared skeleton for lab5
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
from typing import Annotated
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
|
||||
from app.domain.chats import create_chat, get_chat, list_chats
|
||||
from app.endpoints.dependencies import CurrentUser, DbSession
|
||||
from app.schemas.chat import Chat, ChatPage, CreateChat
|
||||
|
||||
router = APIRouter(prefix="/api/v1/chats", tags=["chats"])
|
||||
|
||||
|
||||
@router.post("", status_code=201)
|
||||
async def create_new_chat(
|
||||
new_chat: CreateChat, creator: CurrentUser, session: DbSession
|
||||
) -> Chat:
|
||||
return await create_chat(session, creator, new_chat)
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_user_chats(
|
||||
user: CurrentUser,
|
||||
session: DbSession,
|
||||
limit: Annotated[int, Query(ge=1, le=100)] = 50,
|
||||
cursor: Annotated[str | None, Query(min_length=1)] = None,
|
||||
) -> ChatPage:
|
||||
return await list_chats(session, user, cursor, limit)
|
||||
|
||||
|
||||
@router.get("/{chat_id}")
|
||||
async def get_chat_by_id(chat_id: UUID, user: CurrentUser, session: DbSession) -> Chat:
|
||||
return await get_chat(session, user, chat_id)
|
||||
Reference in New Issue
Block a user