внес правки
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-24 10:56:29 +03:00
parent 6dbc2da1ca
commit 5b15688149
19 changed files with 356 additions and 181 deletions
+11 -3
View File
@@ -10,7 +10,6 @@ from app.models.chat import Chat, ChatMember
from app.models.user import User
from app.security import get_current_user
from app.dependencies import get_session
from app.pagination import paginate
router = APIRouter(prefix="/api/v1/chats/{chat_id}/messages", tags=["messages"])
@@ -78,13 +77,22 @@ async def list_messages(
await check_chat_access(chat_id, user.id, session)
offset = int(cursor) if cursor else 0
result = await session.execute(
select(Message)
.where(Message.chat_id == chat_id)
.order_by(Message.created_at, Message.id)
.limit(limit + 1)
.offset(offset)
)
msgs = result.scalars().all()
has_next = len(msgs) > limit
if has_next:
msgs = msgs[:limit]
my_messages = [
{
"id": m.id,
@@ -95,5 +103,5 @@ async def list_messages(
} for m in msgs
]
page, next_cursor = paginate(my_messages, limit, cursor)
return {"items": page, "next_cursor": next_cursor}
next_cursor = str(offset + limit) if has_next else None
return {"items": my_messages, "next_cursor": next_cursor}