|
@@ -2,7 +2,6 @@ from fastapi import Depends, Request, HTTPException, status
|
|
from datetime import datetime, timedelta
|
|
from datetime import datetime, timedelta
|
|
from typing import List, Union, Optional
|
|
from typing import List, Union, Optional
|
|
|
|
|
|
-from apps.webui.internal.db import get_db
|
|
|
|
from utils.utils import get_current_user, get_admin_user
|
|
from utils.utils import get_current_user, get_admin_user
|
|
from fastapi import APIRouter
|
|
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
from pydantic import BaseModel
|
|
@@ -45,9 +44,9 @@ router = APIRouter()
|
|
@router.get("/", response_model=List[ChatTitleIdResponse])
|
|
@router.get("/", response_model=List[ChatTitleIdResponse])
|
|
@router.get("/list", response_model=List[ChatTitleIdResponse])
|
|
@router.get("/list", response_model=List[ChatTitleIdResponse])
|
|
async def get_session_user_chat_list(
|
|
async def get_session_user_chat_list(
|
|
- user=Depends(get_current_user), skip: int = 0, limit: int = 50, db=Depends(get_db)
|
|
|
|
|
|
+ user=Depends(get_current_user), skip: int = 0, limit: int = 50
|
|
):
|
|
):
|
|
- return Chats.get_chat_list_by_user_id(db, user.id, skip, limit)
|
|
|
|
|
|
+ return Chats.get_chat_list_by_user_id(user.id, skip, limit)
|
|
|
|
|
|
|
|
|
|
############################
|
|
############################
|
|
@@ -57,7 +56,7 @@ async def get_session_user_chat_list(
|
|
|
|
|
|
@router.delete("/", response_model=bool)
|
|
@router.delete("/", response_model=bool)
|
|
async def delete_all_user_chats(
|
|
async def delete_all_user_chats(
|
|
- request: Request, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ request: Request, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
|
|
|
|
if (
|
|
if (
|
|
@@ -69,7 +68,7 @@ async def delete_all_user_chats(
|
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
)
|
|
)
|
|
|
|
|
|
- result = Chats.delete_chats_by_user_id(db, user.id)
|
|
|
|
|
|
+ result = Chats.delete_chats_by_user_id(user.id)
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
|
|
@@ -84,10 +83,9 @@ async def get_user_chat_list_by_user_id(
|
|
user=Depends(get_admin_user),
|
|
user=Depends(get_admin_user),
|
|
skip: int = 0,
|
|
skip: int = 0,
|
|
limit: int = 50,
|
|
limit: int = 50,
|
|
- db=Depends(get_db),
|
|
|
|
):
|
|
):
|
|
return Chats.get_chat_list_by_user_id(
|
|
return Chats.get_chat_list_by_user_id(
|
|
- db, user_id, include_archived=True, skip=skip, limit=limit
|
|
|
|
|
|
+ user_id, include_archived=True, skip=skip, limit=limit
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -98,10 +96,10 @@ async def get_user_chat_list_by_user_id(
|
|
|
|
|
|
@router.post("/new", response_model=Optional[ChatResponse])
|
|
@router.post("/new", response_model=Optional[ChatResponse])
|
|
async def create_new_chat(
|
|
async def create_new_chat(
|
|
- form_data: ChatForm, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ form_data: ChatForm, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
try:
|
|
try:
|
|
- chat = Chats.insert_new_chat(db, user.id, form_data)
|
|
|
|
|
|
+ chat = Chats.insert_new_chat(user.id, form_data)
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
except Exception as e:
|
|
except Exception as e:
|
|
log.exception(e)
|
|
log.exception(e)
|
|
@@ -116,10 +114,10 @@ async def create_new_chat(
|
|
|
|
|
|
|
|
|
|
@router.get("/all", response_model=List[ChatResponse])
|
|
@router.get("/all", response_model=List[ChatResponse])
|
|
-async def get_user_chats(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
+async def get_user_chats(user=Depends(get_current_user)):
|
|
return [
|
|
return [
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
- for chat in Chats.get_chats_by_user_id(db, user.id)
|
|
|
|
|
|
+ for chat in Chats.get_chats_by_user_id(user.id)
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
@@ -129,10 +127,10 @@ async def get_user_chats(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
|
|
|
|
@router.get("/all/archived", response_model=List[ChatResponse])
|
|
@router.get("/all/archived", response_model=List[ChatResponse])
|
|
-async def get_user_archived_chats(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
+async def get_user_archived_chats(user=Depends(get_current_user)):
|
|
return [
|
|
return [
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
- for chat in Chats.get_archived_chats_by_user_id(db, user.id)
|
|
|
|
|
|
+ for chat in Chats.get_archived_chats_by_user_id(user.id)
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
@@ -142,7 +140,7 @@ async def get_user_archived_chats(user=Depends(get_current_user), db=Depends(get
|
|
|
|
|
|
|
|
|
|
@router.get("/all/db", response_model=List[ChatResponse])
|
|
@router.get("/all/db", response_model=List[ChatResponse])
|
|
-async def get_all_user_chats_in_db(user=Depends(get_admin_user), db=Depends(get_db)):
|
|
|
|
|
|
+async def get_all_user_chats_in_db(user=Depends(get_admin_user)):
|
|
if not ENABLE_ADMIN_EXPORT:
|
|
if not ENABLE_ADMIN_EXPORT:
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
@@ -150,7 +148,7 @@ async def get_all_user_chats_in_db(user=Depends(get_admin_user), db=Depends(get_
|
|
)
|
|
)
|
|
return [
|
|
return [
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
- for chat in Chats.get_chats(db)
|
|
|
|
|
|
+ for chat in Chats.get_chats()
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
@@ -161,9 +159,9 @@ async def get_all_user_chats_in_db(user=Depends(get_admin_user), db=Depends(get_
|
|
|
|
|
|
@router.get("/archived", response_model=List[ChatTitleIdResponse])
|
|
@router.get("/archived", response_model=List[ChatTitleIdResponse])
|
|
async def get_archived_session_user_chat_list(
|
|
async def get_archived_session_user_chat_list(
|
|
- user=Depends(get_current_user), skip: int = 0, limit: int = 50, db=Depends(get_db)
|
|
|
|
|
|
+ user=Depends(get_current_user), skip: int = 0, limit: int = 50
|
|
):
|
|
):
|
|
- return Chats.get_archived_chat_list_by_user_id(db, user.id, skip, limit)
|
|
|
|
|
|
+ return Chats.get_archived_chat_list_by_user_id(user.id, skip, limit)
|
|
|
|
|
|
|
|
|
|
############################
|
|
############################
|
|
@@ -172,8 +170,8 @@ async def get_archived_session_user_chat_list(
|
|
|
|
|
|
|
|
|
|
@router.post("/archive/all", response_model=bool)
|
|
@router.post("/archive/all", response_model=bool)
|
|
-async def archive_all_chats(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
- return Chats.archive_all_chats_by_user_id(db, user.id)
|
|
|
|
|
|
+async def archive_all_chats(user=Depends(get_current_user)):
|
|
|
|
+ return Chats.archive_all_chats_by_user_id(user.id)
|
|
|
|
|
|
|
|
|
|
############################
|
|
############################
|
|
@@ -183,7 +181,7 @@ async def archive_all_chats(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
@router.get("/share/{share_id}", response_model=Optional[ChatResponse])
|
|
@router.get("/share/{share_id}", response_model=Optional[ChatResponse])
|
|
async def get_shared_chat_by_id(
|
|
async def get_shared_chat_by_id(
|
|
- share_id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ share_id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
if user.role == "pending":
|
|
if user.role == "pending":
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
@@ -191,9 +189,9 @@ async def get_shared_chat_by_id(
|
|
)
|
|
)
|
|
|
|
|
|
if user.role == "user":
|
|
if user.role == "user":
|
|
- chat = Chats.get_chat_by_share_id(db, share_id)
|
|
|
|
|
|
+ chat = Chats.get_chat_by_share_id(share_id)
|
|
elif user.role == "admin":
|
|
elif user.role == "admin":
|
|
- chat = Chats.get_chat_by_id(db, share_id)
|
|
|
|
|
|
+ chat = Chats.get_chat_by_id(share_id)
|
|
|
|
|
|
if chat:
|
|
if chat:
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
@@ -216,23 +214,23 @@ class TagNameForm(BaseModel):
|
|
|
|
|
|
@router.post("/tags", response_model=List[ChatTitleIdResponse])
|
|
@router.post("/tags", response_model=List[ChatTitleIdResponse])
|
|
async def get_user_chat_list_by_tag_name(
|
|
async def get_user_chat_list_by_tag_name(
|
|
- form_data: TagNameForm, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ form_data: TagNameForm, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
|
|
|
|
print(form_data)
|
|
print(form_data)
|
|
chat_ids = [
|
|
chat_ids = [
|
|
chat_id_tag.chat_id
|
|
chat_id_tag.chat_id
|
|
for chat_id_tag in Tags.get_chat_ids_by_tag_name_and_user_id(
|
|
for chat_id_tag in Tags.get_chat_ids_by_tag_name_and_user_id(
|
|
- db, form_data.name, user.id
|
|
|
|
|
|
+ form_data.name, user.id
|
|
)
|
|
)
|
|
]
|
|
]
|
|
|
|
|
|
chats = Chats.get_chat_list_by_chat_ids(
|
|
chats = Chats.get_chat_list_by_chat_ids(
|
|
- db, chat_ids, form_data.skip, form_data.limit
|
|
|
|
|
|
+ chat_ids, form_data.skip, form_data.limit
|
|
)
|
|
)
|
|
|
|
|
|
if len(chats) == 0:
|
|
if len(chats) == 0:
|
|
- Tags.delete_tag_by_tag_name_and_user_id(db, form_data.name, user.id)
|
|
|
|
|
|
+ Tags.delete_tag_by_tag_name_and_user_id(form_data.name, user.id)
|
|
|
|
|
|
return chats
|
|
return chats
|
|
|
|
|
|
@@ -243,9 +241,9 @@ async def get_user_chat_list_by_tag_name(
|
|
|
|
|
|
|
|
|
|
@router.get("/tags/all", response_model=List[TagModel])
|
|
@router.get("/tags/all", response_model=List[TagModel])
|
|
-async def get_all_tags(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
+async def get_all_tags(user=Depends(get_current_user)):
|
|
try:
|
|
try:
|
|
- tags = Tags.get_tags_by_user_id(db, user.id)
|
|
|
|
|
|
+ tags = Tags.get_tags_by_user_id(user.id)
|
|
return tags
|
|
return tags
|
|
except Exception as e:
|
|
except Exception as e:
|
|
log.exception(e)
|
|
log.exception(e)
|
|
@@ -260,8 +258,8 @@ async def get_all_tags(user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
|
|
|
|
|
|
@router.get("/{id}", response_model=Optional[ChatResponse])
|
|
@router.get("/{id}", response_model=Optional[ChatResponse])
|
|
-async def get_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+async def get_chat_by_id(id: str, user=Depends(get_current_user)):
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
|
|
|
|
if chat:
|
|
if chat:
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
@@ -278,13 +276,13 @@ async def get_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(get
|
|
|
|
|
|
@router.post("/{id}", response_model=Optional[ChatResponse])
|
|
@router.post("/{id}", response_model=Optional[ChatResponse])
|
|
async def update_chat_by_id(
|
|
async def update_chat_by_id(
|
|
- id: str, form_data: ChatForm, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ id: str, form_data: ChatForm, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
if chat:
|
|
if chat:
|
|
updated_chat = {**json.loads(chat.chat), **form_data.chat}
|
|
updated_chat = {**json.loads(chat.chat), **form_data.chat}
|
|
|
|
|
|
- chat = Chats.update_chat_by_id(db, id, updated_chat)
|
|
|
|
|
|
+ chat = Chats.update_chat_by_id(id, updated_chat)
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
else:
|
|
else:
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
@@ -300,11 +298,11 @@ async def update_chat_by_id(
|
|
|
|
|
|
@router.delete("/{id}", response_model=bool)
|
|
@router.delete("/{id}", response_model=bool)
|
|
async def delete_chat_by_id(
|
|
async def delete_chat_by_id(
|
|
- request: Request, id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ request: Request, id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
|
|
|
|
if user.role == "admin":
|
|
if user.role == "admin":
|
|
- result = Chats.delete_chat_by_id(db, id)
|
|
|
|
|
|
+ result = Chats.delete_chat_by_id(id)
|
|
return result
|
|
return result
|
|
else:
|
|
else:
|
|
if not request.app.state.config.USER_PERMISSIONS["chat"]["deletion"]:
|
|
if not request.app.state.config.USER_PERMISSIONS["chat"]["deletion"]:
|
|
@@ -313,7 +311,7 @@ async def delete_chat_by_id(
|
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
)
|
|
)
|
|
|
|
|
|
- result = Chats.delete_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ result = Chats.delete_chat_by_id_and_user_id(id, user.id)
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
|
|
@@ -323,8 +321,8 @@ async def delete_chat_by_id(
|
|
|
|
|
|
|
|
|
|
@router.get("/{id}/clone", response_model=Optional[ChatResponse])
|
|
@router.get("/{id}/clone", response_model=Optional[ChatResponse])
|
|
-async def clone_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+async def clone_chat_by_id(id: str, user=Depends(get_current_user)):
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
if chat:
|
|
if chat:
|
|
|
|
|
|
chat_body = json.loads(chat.chat)
|
|
chat_body = json.loads(chat.chat)
|
|
@@ -335,7 +333,7 @@ async def clone_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(g
|
|
"title": f"Clone of {chat.title}",
|
|
"title": f"Clone of {chat.title}",
|
|
}
|
|
}
|
|
|
|
|
|
- chat = Chats.insert_new_chat(db, user.id, ChatForm(**{"chat": updated_chat}))
|
|
|
|
|
|
+ chat = Chats.insert_new_chat(user.id, ChatForm(**{"chat": updated_chat}))
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
else:
|
|
else:
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
@@ -350,11 +348,11 @@ async def clone_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(g
|
|
|
|
|
|
@router.get("/{id}/archive", response_model=Optional[ChatResponse])
|
|
@router.get("/{id}/archive", response_model=Optional[ChatResponse])
|
|
async def archive_chat_by_id(
|
|
async def archive_chat_by_id(
|
|
- id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
if chat:
|
|
if chat:
|
|
- chat = Chats.toggle_chat_archive_by_id(db, id)
|
|
|
|
|
|
+ chat = Chats.toggle_chat_archive_by_id(id)
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
return ChatResponse(**{**chat.model_dump(), "chat": json.loads(chat.chat)})
|
|
else:
|
|
else:
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
@@ -368,16 +366,16 @@ async def archive_chat_by_id(
|
|
|
|
|
|
|
|
|
|
@router.post("/{id}/share", response_model=Optional[ChatResponse])
|
|
@router.post("/{id}/share", response_model=Optional[ChatResponse])
|
|
-async def share_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(get_db)):
|
|
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+async def share_chat_by_id(id: str, user=Depends(get_current_user)):
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
if chat:
|
|
if chat:
|
|
if chat.share_id:
|
|
if chat.share_id:
|
|
- shared_chat = Chats.update_shared_chat_by_chat_id(db, chat.id)
|
|
|
|
|
|
+ shared_chat = Chats.update_shared_chat_by_chat_id(chat.id)
|
|
return ChatResponse(
|
|
return ChatResponse(
|
|
**{**shared_chat.model_dump(), "chat": json.loads(shared_chat.chat)}
|
|
**{**shared_chat.model_dump(), "chat": json.loads(shared_chat.chat)}
|
|
)
|
|
)
|
|
|
|
|
|
- shared_chat = Chats.insert_shared_chat_by_chat_id(db, chat.id)
|
|
|
|
|
|
+ shared_chat = Chats.insert_shared_chat_by_chat_id(chat.id)
|
|
if not shared_chat:
|
|
if not shared_chat:
|
|
raise HTTPException(
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
@@ -401,15 +399,15 @@ async def share_chat_by_id(id: str, user=Depends(get_current_user), db=Depends(g
|
|
|
|
|
|
@router.delete("/{id}/share", response_model=Optional[bool])
|
|
@router.delete("/{id}/share", response_model=Optional[bool])
|
|
async def delete_shared_chat_by_id(
|
|
async def delete_shared_chat_by_id(
|
|
- id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- chat = Chats.get_chat_by_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
|
if chat:
|
|
if chat:
|
|
if not chat.share_id:
|
|
if not chat.share_id:
|
|
return False
|
|
return False
|
|
|
|
|
|
- result = Chats.delete_shared_chat_by_chat_id(db, id)
|
|
|
|
- update_result = Chats.update_chat_share_id_by_id(db, id, None)
|
|
|
|
|
|
+ result = Chats.delete_shared_chat_by_chat_id(id)
|
|
|
|
+ update_result = Chats.update_chat_share_id_by_id(id, None)
|
|
|
|
|
|
return result and update_result != None
|
|
return result and update_result != None
|
|
else:
|
|
else:
|
|
@@ -426,9 +424,9 @@ async def delete_shared_chat_by_id(
|
|
|
|
|
|
@router.get("/{id}/tags", response_model=List[TagModel])
|
|
@router.get("/{id}/tags", response_model=List[TagModel])
|
|
async def get_chat_tags_by_id(
|
|
async def get_chat_tags_by_id(
|
|
- id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- tags = Tags.get_tags_by_chat_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ tags = Tags.get_tags_by_chat_id_and_user_id(id, user.id)
|
|
|
|
|
|
if tags != None:
|
|
if tags != None:
|
|
return tags
|
|
return tags
|
|
@@ -447,13 +445,12 @@ async def get_chat_tags_by_id(
|
|
async def add_chat_tag_by_id(
|
|
async def add_chat_tag_by_id(
|
|
id: str,
|
|
id: str,
|
|
form_data: ChatIdTagForm,
|
|
form_data: ChatIdTagForm,
|
|
- user=Depends(get_current_user),
|
|
|
|
- db=Depends(get_db),
|
|
|
|
|
|
+ user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- tags = Tags.get_tags_by_chat_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ tags = Tags.get_tags_by_chat_id_and_user_id(id, user.id)
|
|
|
|
|
|
if form_data.tag_name not in tags:
|
|
if form_data.tag_name not in tags:
|
|
- tag = Tags.add_tag_to_chat(db, user.id, form_data)
|
|
|
|
|
|
+ tag = Tags.add_tag_to_chat(user.id, form_data)
|
|
|
|
|
|
if tag:
|
|
if tag:
|
|
return tag
|
|
return tag
|
|
@@ -478,10 +475,9 @@ async def delete_chat_tag_by_id(
|
|
id: str,
|
|
id: str,
|
|
form_data: ChatIdTagForm,
|
|
form_data: ChatIdTagForm,
|
|
user=Depends(get_current_user),
|
|
user=Depends(get_current_user),
|
|
- db=Depends(get_db),
|
|
|
|
):
|
|
):
|
|
result = Tags.delete_tag_by_tag_name_and_chat_id_and_user_id(
|
|
result = Tags.delete_tag_by_tag_name_and_chat_id_and_user_id(
|
|
- db, form_data.tag_name, id, user.id
|
|
|
|
|
|
+ form_data.tag_name, id, user.id
|
|
)
|
|
)
|
|
|
|
|
|
if result:
|
|
if result:
|
|
@@ -499,9 +495,9 @@ async def delete_chat_tag_by_id(
|
|
|
|
|
|
@router.delete("/{id}/tags/all", response_model=Optional[bool])
|
|
@router.delete("/{id}/tags/all", response_model=Optional[bool])
|
|
async def delete_all_chat_tags_by_id(
|
|
async def delete_all_chat_tags_by_id(
|
|
- id: str, user=Depends(get_current_user), db=Depends(get_db)
|
|
|
|
|
|
+ id: str, user=Depends(get_current_user)
|
|
):
|
|
):
|
|
- result = Tags.delete_tags_by_chat_id_and_user_id(db, id, user.id)
|
|
|
|
|
|
+ result = Tags.delete_tags_by_chat_id_and_user_id(id, user.id)
|
|
|
|
|
|
if result:
|
|
if result:
|
|
return result
|
|
return result
|