Перенести реализацию мессенджера из ЛР 6

Файлы скопированы без изменений из solution/BPI2301-Vozzhin
репозитория mtusi2026lab6. Доработки ЛР 7 идут отдельными коммитами.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-12-03 19:48:41 +05:00
co-authored by Claude Opus 5.5
parent 20afc2c790
commit 31d441184b
92 changed files with 6153 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
from typing import Optional
from uuid import UUID
from fastapi import APIRouter, Depends, Query
from ...domain.models import User
from ...services.chats import ChatService
from .. import cursors
from ..deps import chat_service, current_user
from ..schemas import (
LIMIT_DEFAULT,
LIMIT_MAX,
LIMIT_MIN,
ChatOut,
ChatPageOut,
CreateChat,
)
router = APIRouter(prefix='/api/v1/chats', tags=['chats'])
@router.post('', status_code=201, response_model=ChatOut)
async def create(
body: CreateChat,
actor: User = Depends(current_user),
chats: ChatService = Depends(chat_service),
) -> ChatOut:
return ChatOut.from_domain(await chats.create(actor, body.title, body.member_ids))
@router.get('', response_model=ChatPageOut)
async def page(
actor: User = Depends(current_user),
chats: ChatService = Depends(chat_service),
limit: int = Query(LIMIT_DEFAULT, ge=LIMIT_MIN, le=LIMIT_MAX),
cursor: Optional[str] = Query(None, min_length=1, max_length=cursors.MAX_LENGTH),
) -> ChatPageOut:
scope = f'chats:{actor.id}'
after = cursors.decode(scope, cursor) if cursor is not None else None
return ChatPageOut.from_domain(await chats.page(actor, after, limit), scope)
@router.get('/{chat_id}', response_model=ChatOut)
async def get(
chat_id: UUID,
actor: User = Depends(current_user),
chats: ChatService = Depends(chat_service),
) -> ChatOut:
return ChatOut.from_domain(await chats.get(actor, chat_id))