adding works, viewing works, but viewing specific blogs are not implemented yet.
This commit is contained in:
@@ -137,3 +137,20 @@ pub fn save_blog(
|
||||
create_blog_db(conn, title, content, linked_app_ids)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_blogs(conn: &mut SqliteConnection) -> Vec<models::Blog> {
|
||||
use crate::db::schema::blog;
|
||||
|
||||
blog::table
|
||||
.load::<models::Blog>(conn)
|
||||
.expect("Error loading apps")
|
||||
}
|
||||
|
||||
pub fn get_apps_by_ids(conn: &mut SqliteConnection, ids: &[String]) -> Vec<models::App> {
|
||||
use crate::db::schema::app;
|
||||
|
||||
app::table
|
||||
.filter(app::id.eq_any(ids))
|
||||
.load::<models::App>(conn)
|
||||
.expect("Error loading apps by ids")
|
||||
}
|
||||
|
||||
+39
-1
@@ -74,6 +74,36 @@ async fn ping(address: &str) -> Result<bool, String> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
struct TempBlog {
|
||||
id: String,
|
||||
title: String,
|
||||
content: String,
|
||||
linked_app_ids: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_blogs() -> Vec<TempBlog> {
|
||||
// I'll need to decode the linked_app_ids from a json encoded string to a Vec<String>.
|
||||
let mut conn = establish_connection();
|
||||
let encoded_blogs = db::get_all_blogs(&mut conn);
|
||||
let mut decoded_blogs: Vec<TempBlog> = Vec::new();
|
||||
encoded_blogs.iter().for_each(|blog| {
|
||||
let linked_app_ids: Option<Vec<String>> = match &blog.reference {
|
||||
Some(ids) => serde_json::from_str(ids).ok(),
|
||||
None => None,
|
||||
};
|
||||
decoded_blogs.push(TempBlog {
|
||||
id: blog.id.clone(),
|
||||
title: blog.title.clone(),
|
||||
content: blog.content.clone(),
|
||||
linked_app_ids,
|
||||
});
|
||||
});
|
||||
|
||||
decoded_blogs
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_blog(
|
||||
id: Option<&str>,
|
||||
@@ -85,6 +115,12 @@ fn save_blog(
|
||||
db::save_blog(&mut conn, id, title, content, linked_app_ids.as_deref())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_apps_by_id(ids: Vec<String>) -> Vec<App> {
|
||||
let mut conn = establish_connection();
|
||||
db::get_apps_by_ids(&mut conn, &ids)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
@@ -94,7 +130,9 @@ pub fn run() {
|
||||
get_app,
|
||||
delete_apps,
|
||||
ping,
|
||||
save_blog
|
||||
get_blogs,
|
||||
save_blog,
|
||||
get_apps_by_id
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user