From a6c38ff933bd124a7b3682d134da3eefbab2bcdd Mon Sep 17 00:00:00 2001 From: Martin <1224973+mavaa@users.noreply.github.com> Date: Sat, 25 Mar 2023 12:57:09 +0100 Subject: [PATCH] Implementing deletion of chat (#39) * Implementing deletion of chat * svelte refactoring of delete code --------- Co-authored-by: Nathan Sarrazin --- api/main.py | 9 ++++++++ web/src/routes/+layout.svelte | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/api/main.py b/api/main.py index ba1d6c2..1deeec6 100644 --- a/api/main.py +++ b/api/main.py @@ -143,6 +143,15 @@ async def get_specific_chat(chat_id: str): return chat +@app.delete("/chat/{chat_id}", tags=["chats"]) +async def delete_chat(chat_id: str): + chat = await Chat.get(chat_id) + deleted_chat = await chat.delete() + + if deleted_chat: + return {"message": f"Deleted chat with id: {chat_id}"} + else: + raise HTTPException(status_code=404, detail="No chat found with the given id.") async def on_close(chat, prompt, answer=None, error=None): question = await Question(question=prompt.rstrip(), diff --git a/web/src/routes/+layout.svelte b/web/src/routes/+layout.svelte index 5e8fa68..6724dd6 100644 --- a/web/src/routes/+layout.svelte +++ b/web/src/routes/+layout.svelte @@ -1,8 +1,26 @@