feat: establish PostgreSQL lab2 baseline with benchmark tooling
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from src.api import schemas
|
||||
from src.api.deps import ChatServiceDep, CurrentUser, PageDep
|
||||
|
||||
router = APIRouter(prefix="/chats", tags=["chats"])
|
||||
|
||||
|
||||
@router.post("", status_code=201, response_model=schemas.Chat)
|
||||
async def create_chat(
|
||||
user: CurrentUser,
|
||||
body: schemas.CreateChat,
|
||||
chats: ChatServiceDep,
|
||||
) -> schemas.Chat:
|
||||
chat = await chats.create(
|
||||
creator_id=user.id,
|
||||
title=body.title,
|
||||
member_ids=body.member_ids,
|
||||
)
|
||||
return schemas.Chat.model_validate(chat)
|
||||
|
||||
|
||||
@router.get("", response_model=schemas.ChatPage)
|
||||
async def list_chats(
|
||||
user: CurrentUser,
|
||||
page: PageDep,
|
||||
chats: ChatServiceDep,
|
||||
) -> schemas.ChatPage:
|
||||
result = await chats.list_for(
|
||||
user_id=user.id,
|
||||
limit=page.limit,
|
||||
cursor=page.cursor,
|
||||
)
|
||||
return schemas.ChatPage.model_validate(result)
|
||||
|
||||
|
||||
@router.get("/{chat_id}", response_model=schemas.Chat)
|
||||
async def get_chat(
|
||||
user: CurrentUser,
|
||||
chat_id: UUID,
|
||||
chats: ChatServiceDep,
|
||||
) -> schemas.Chat:
|
||||
chat = await chats.get(chat_id=chat_id, user_id=user.id)
|
||||
return schemas.Chat.model_validate(chat)
|
||||
Reference in New Issue
Block a user