feat: add message history and concurrent writes

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-01 21:27:53 +03:00
parent ac739713b3
commit 55ec45cc3d
4 changed files with 154 additions and 1 deletions
+18 -1
View File
@@ -4,7 +4,7 @@ from uuid import UUID
from fastapi import APIRouter, Depends, Header, HTTPException, Query
from .models import CreateChat, CreateUser
from .models import CreateChat, CreateMessage, CreateUser
from .store import store
router = APIRouter()
@@ -51,3 +51,20 @@ def list_chats(
@router.get("/api/v1/chats/{chat_id}")
def get_chat(chat_id: UUID, actor: dict = Depends(current_user)):
return store.chat(actor["id"], str(chat_id))
@router.post("/api/v1/chats/{chat_id}/messages", status_code=201)
def create_message(chat_id: UUID, body: CreateMessage, actor: dict = Depends(current_user)):
return store.create_message(actor["id"], str(chat_id), body.text)
@router.get("/api/v1/chats/{chat_id}/messages")
def list_messages(
chat_id: UUID,
limit: str = Query("50"),
cursor: str | None = Query(None, min_length=1),
actor: dict = Depends(current_user),
):
if not limit.isdecimal() or not 1 <= int(limit) <= 100:
raise HTTPException(400)
return store.list_messages(actor["id"], str(chat_id), int(limit), cursor)