forked from mtusi2026/mtusi2026lab2
я надеюсь я исправила поставьте зачет
This commit is contained in:
@@ -211,17 +211,15 @@ def create_chat(auth: Auth = Depends(authenticated), body: RawBody = Depends(raw
|
||||
chat = repo.create_chat(conn, auth.user_id, title, members)
|
||||
return repo.chat_json(chat)
|
||||
|
||||
|
||||
@app.get("/api/v1/chats")
|
||||
def list_chats(request: Request, auth: Auth = Depends(authenticated)):
|
||||
limit = validation.limit_param(request.query_params)
|
||||
raw = request.query_params.get("cursor")
|
||||
after = cursor.decode(raw, "chats", auth.user_id) if raw else None
|
||||
after = cursor.decode(raw, "chats", auth.user_id) if raw is not None else None
|
||||
with db.connection() as conn:
|
||||
items, nxt = repo.list_chats(conn, auth.user_id, after, limit)
|
||||
return {"items": items, "next_cursor": nxt}
|
||||
|
||||
|
||||
@app.get("/api/v1/chats/{chat_id}")
|
||||
def get_chat(chat_id: str, auth: Auth = Depends(authenticated)):
|
||||
cid = validation.require_uuid(chat_id, "chat_id")
|
||||
@@ -251,9 +249,9 @@ def list_messages(chat_id: str, request: Request, auth: Auth = Depends(authentic
|
||||
cid = validation.require_uuid(chat_id, "chat_id")
|
||||
limit = validation.limit_param(request.query_params)
|
||||
raw = request.query_params.get("cursor")
|
||||
after = cursor.decode(raw, "messages", cid) if raw else None
|
||||
after = cursor.decode(raw, "messages", cid) if raw is not None else None
|
||||
with db.connection() as conn:
|
||||
if not repo.is_member(conn, cid, auth.user_id):
|
||||
raise not_found()
|
||||
items, nxt = repo.list_messages(conn, cid, after, limit)
|
||||
return {"items": items, "next_cursor": nxt}
|
||||
return {"items": items, "next_cursor": nxt}
|
||||
Reference in New Issue
Block a user