feat: save tags to chat data

This commit is contained in:
Timothy J. Baek 2024-01-18 02:17:31 -08:00
parent 987685dbf9
commit 1eec176313
4 changed files with 17 additions and 3 deletions

View file

@ -101,7 +101,6 @@ class TagTable:
if tag == None: if tag == None:
tag = self.insert_new_tag(form_data.tag_name, user_id) tag = self.insert_new_tag(form_data.tag_name, user_id)
print(tag)
id = str(uuid.uuid4()) id = str(uuid.uuid4())
chatIdTag = ChatIdTagModel( chatIdTag = ChatIdTagModel(
**{ **{
@ -131,7 +130,6 @@ class TagTable:
.order_by(ChatIdTag.timestamp.desc()) .order_by(ChatIdTag.timestamp.desc())
] ]
print(tag_names)
return [ return [
TagModel(**model_to_dict(tag)) TagModel(**model_to_dict(tag))
for tag in Tag.select().where(Tag.name.in_(tag_names)) for tag in Tag.select().where(Tag.name.in_(tag_names))

View file

@ -134,7 +134,6 @@ async def get_chat_tags_by_id(id: str, user=Depends(get_current_user)):
tags = Tags.get_tags_by_chat_id_and_user_id(id, user.id) tags = Tags.get_tags_by_chat_id_and_user_id(id, user.id)
if tags != None: if tags != None:
print(tags)
return tags return tags
else: else:
raise HTTPException( raise HTTPException(

View file

@ -189,6 +189,7 @@
}, },
messages: messages, messages: messages,
history: history, history: history,
tags: [],
timestamp: Date.now() timestamp: Date.now()
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
@ -690,11 +691,19 @@
const addTag = async (tagName) => { const addTag = async (tagName) => {
const res = await addTagById(localStorage.token, $chatId, tagName); const res = await addTagById(localStorage.token, $chatId, tagName);
tags = await getTags(); tags = await getTags();
chat = await updateChatById(localStorage.token, $chatId, {
tags: tags
});
}; };
const deleteTag = async (tagName) => { const deleteTag = async (tagName) => {
const res = await deleteTagById(localStorage.token, $chatId, tagName); const res = await deleteTagById(localStorage.token, $chatId, tagName);
tags = await getTags(); tags = await getTags();
chat = await updateChatById(localStorage.token, $chatId, {
tags: tags
});
}; };
const setChatTitle = async (_chatId, _title) => { const setChatTitle = async (_chatId, _title) => {

View file

@ -707,11 +707,19 @@
const addTag = async (tagName) => { const addTag = async (tagName) => {
const res = await addTagById(localStorage.token, $chatId, tagName); const res = await addTagById(localStorage.token, $chatId, tagName);
tags = await getTags(); tags = await getTags();
chat = await updateChatById(localStorage.token, $chatId, {
tags: tags.map((tag) => tag.name)
});
}; };
const deleteTag = async (tagName) => { const deleteTag = async (tagName) => {
const res = await deleteTagById(localStorage.token, $chatId, tagName); const res = await deleteTagById(localStorage.token, $chatId, tagName);
tags = await getTags(); tags = await getTags();
chat = await updateChatById(localStorage.token, $chatId, {
tags: tags.map((tag) => tag.name)
});
}; };
onMount(async () => { onMount(async () => {