forked from mtusi2026/mtusi2026lab2
финальные evidence для lab2 + кэширование
This commit is contained in:
+4
-3
@@ -171,10 +171,9 @@ async def login(
|
||||
raise HTTPException(
|
||||
status_code=401, detail="Unauthorized", headers={"WWW-Authenticate": basic_challenge}
|
||||
)
|
||||
token = generate_token()
|
||||
expires = datetime.now(timezone.utc) + timedelta(seconds=SESSION_TTL)
|
||||
token = await create_session(str(user.id))
|
||||
await db.commit()
|
||||
|
||||
return {
|
||||
"token": token,
|
||||
"token_type": "Bearer",
|
||||
@@ -271,6 +270,7 @@ async def list_messages(
|
||||
chat = await chats_repo.get_if_member(db, chat_id, user.id)
|
||||
if chat is None:
|
||||
raise HTTPException(404, "Chat not found")
|
||||
|
||||
parsed = None
|
||||
if cursor is not None:
|
||||
try:
|
||||
@@ -278,11 +278,12 @@ async def list_messages(
|
||||
parsed = (datetime.fromisoformat(c_created), UUID(c_id))
|
||||
except Exception:
|
||||
raise HTTPException(400, "Invalid cursor")
|
||||
|
||||
rows, next_cursor = await messages_repo.list_page(db, chat_id, limit, parsed)
|
||||
|
||||
nxt = f"{next_cursor[0].isoformat()}|{next_cursor[1]}" if next_cursor else None
|
||||
return {"items": [_msg_json(m) for m in rows], "next_cursor": nxt}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user