-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from takanotume24/feature/44__fix_the_position…
…_of_the_session_list Feature/44 fix the position of the session list
- Loading branch information
Showing
24 changed files
with
476 additions
and
314 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
pub struct ChatResponse { | ||
pub response: String, | ||
pub created_at: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct RawDatabaseChatEntry { | ||
pub session_id: String, | ||
pub question: String, | ||
pub answer: String, | ||
pub created_at: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct SessionId(pub String); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::database::Database; | ||
use crate::get_db_connection::get_db_connection; | ||
use crate::models::ChatHistory; | ||
use crate::schema::chat_history::dsl::*; | ||
use diesel::prelude::*; | ||
use tauri::State; | ||
use crate::app_type::RawDatabaseChatEntry; | ||
use tauri::async_runtime::block_on; | ||
|
||
#[tauri::command] | ||
pub fn get_chat_history_by_session( | ||
db: State<'_, Database>, | ||
target_session_id: String, | ||
) -> Result<Vec<RawDatabaseChatEntry>, String> { | ||
// Use block_on to run the async code synchronously | ||
block_on(async { | ||
// Use the helper function to get a mutable connection | ||
let mut conn = get_db_connection(&db)?; | ||
|
||
// Filter the chat history by the specific session_id | ||
let results = chat_history | ||
.filter(session_id.eq(target_session_id)) | ||
.load::<ChatHistory>(&mut conn) | ||
.map_err(|e| e.to_string())?; | ||
|
||
// Transform results into a vector of RawDatabaseChatEntry | ||
let rows: Vec<RawDatabaseChatEntry> = results | ||
.into_iter() | ||
.map(|chat| RawDatabaseChatEntry { | ||
session_id: chat.session_id.clone(), | ||
question: chat.question.clone(), | ||
answer: chat.answer.clone(), | ||
created_at: chat.created_at.to_string(), | ||
}) | ||
.collect(); | ||
|
||
Ok(rows) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::database::Database; | ||
use crate::get_db_connection::get_db_connection; | ||
use crate::schema::chat_history::dsl::*; | ||
use diesel::prelude::*; | ||
use tauri::State; | ||
use tauri::async_runtime::block_on; | ||
use crate::app_type::SessionId; | ||
|
||
#[tauri::command] | ||
pub fn get_session_id_list( | ||
db: State<'_, Database>, | ||
) -> Result<Vec<SessionId>, String> { | ||
block_on(async { | ||
let mut conn = get_db_connection(&db)?; | ||
|
||
let results = chat_history | ||
.select(session_id) | ||
.distinct() | ||
.load::<String>(&mut conn) | ||
.map_err(|e| e.to_string())? | ||
.into_iter() | ||
.map(SessionId) | ||
.collect(); | ||
|
||
Ok(results) | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.