changed return type of GET chat

This commit is contained in:
Yannic Kilcher
2023-02-09 08:52:45 +01:00
parent 998be19f2f
commit c53d8e9bce
+10 -2
View File
@@ -67,6 +67,11 @@ class ChatListEntry(pydantic.BaseModel):
id: str id: str
class ChatEntry(pydantic.BaseModel):
id: str
conversation: protocol.Conversation
class ListChatsResponse(pydantic.BaseModel): class ListChatsResponse(pydantic.BaseModel):
chats: list[ChatListEntry] chats: list[ChatListEntry]
@@ -80,6 +85,9 @@ class DbChatEntry(pydantic.BaseModel):
def to_list_entry(self) -> ChatListEntry: def to_list_entry(self) -> ChatListEntry:
return ChatListEntry(id=self.id) return ChatListEntry(id=self.id)
def to_entry(self) -> ChatEntry:
return ChatEntry(id=self.id, conversation=self.conversation)
# TODO: make real database # TODO: make real database
CHATS: dict[str, DbChatEntry] = {} CHATS: dict[str, DbChatEntry] = {}
@@ -103,9 +111,9 @@ async def create_chat(request: CreateChatRequest) -> ChatListEntry:
@app.get("/chat/{id}") @app.get("/chat/{id}")
async def get_chat(id: str) -> protocol.Conversation: async def get_chat(id: str) -> ChatEntry:
"""Allows a client to get the current state of a chat.""" """Allows a client to get the current state of a chat."""
return CHATS[id].conversation return CHATS[id].to_entry()
@app.post("/chat/{id}/message") @app.post("/chat/{id}/message")