From bdd2ac0015354a8b9827923bd79880c59f7071b7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 12 Jun 2024 13:45:13 -0700 Subject: [PATCH] fix/refac: docs --- backend/apps/webui/routers/documents.py | 8 ++++---- src/lib/apis/documents/index.ts | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/apps/webui/routers/documents.py b/backend/apps/webui/routers/documents.py index c5447a3fe..311455390 100644 --- a/backend/apps/webui/routers/documents.py +++ b/backend/apps/webui/routers/documents.py @@ -73,7 +73,7 @@ async def create_new_doc(form_data: DocumentForm, user=Depends(get_admin_user)): ############################ -@router.get("/name/{name}", response_model=Optional[DocumentResponse]) +@router.get("/doc", response_model=Optional[DocumentResponse]) async def get_doc_by_name(name: str, user=Depends(get_current_user)): doc = Documents.get_doc_by_name(name) @@ -105,7 +105,7 @@ class TagDocumentForm(BaseModel): tags: List[dict] -@router.post("/name/{name}/tags", response_model=Optional[DocumentResponse]) +@router.post("/doc/tags", response_model=Optional[DocumentResponse]) async def tag_doc_by_name(form_data: TagDocumentForm, user=Depends(get_current_user)): doc = Documents.update_doc_content_by_name(form_data.name, {"tags": form_data.tags}) @@ -128,7 +128,7 @@ async def tag_doc_by_name(form_data: TagDocumentForm, user=Depends(get_current_u ############################ -@router.post("/name/{name}/update", response_model=Optional[DocumentResponse]) +@router.post("/doc/update", response_model=Optional[DocumentResponse]) async def update_doc_by_name( name: str, form_data: DocumentUpdateForm, user=Depends(get_admin_user) ): @@ -152,7 +152,7 @@ async def update_doc_by_name( ############################ -@router.delete("/name/{name}/delete", response_model=bool) +@router.delete("/doc/delete", response_model=bool) async def delete_doc_by_name(name: str, user=Depends(get_admin_user)): result = Documents.delete_doc_by_name(name) return result diff --git a/src/lib/apis/documents/index.ts b/src/lib/apis/documents/index.ts index 21e0a2643..9d42feb19 100644 --- a/src/lib/apis/documents/index.ts +++ b/src/lib/apis/documents/index.ts @@ -76,7 +76,10 @@ export const getDocs = async (token: string = '') => { export const getDocByName = async (token: string, name: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/documents/name/${name}`, { + const searchParams = new URLSearchParams(); + searchParams.append('name', name); + + const res = await fetch(`${WEBUI_API_BASE_URL}/documents/docs?${searchParams.toString()}`, { method: 'GET', headers: { Accept: 'application/json', @@ -113,7 +116,10 @@ type DocUpdateForm = { export const updateDocByName = async (token: string, name: string, form: DocUpdateForm) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/documents/name/${name}/update`, { + const searchParams = new URLSearchParams(); + searchParams.append('name', name); + + const res = await fetch(`${WEBUI_API_BASE_URL}/documents/doc/update?${searchParams.toString()}`, { method: 'POST', headers: { Accept: 'application/json', @@ -154,7 +160,10 @@ type TagDocForm = { export const tagDocByName = async (token: string, name: string, form: TagDocForm) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/documents/name/${name}/tags`, { + const searchParams = new URLSearchParams(); + searchParams.append('name', name); + + const res = await fetch(`${WEBUI_API_BASE_URL}/documents/doc/tags?${searchParams.toString()}`, { method: 'POST', headers: { Accept: 'application/json', @@ -190,7 +199,10 @@ export const tagDocByName = async (token: string, name: string, form: TagDocForm export const deleteDocByName = async (token: string, name: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/documents/name/${name}/delete`, { + const searchParams = new URLSearchParams(); + searchParams.append('name', name); + + const res = await fetch(`${WEBUI_API_BASE_URL}/documents/doc/delete?${searchParams.toString()}`, { method: 'DELETE', headers: { Accept: 'application/json',