Skip to content
Snippets Groups Projects
Commit 0023680a authored by HGEpro's avatar HGEpro
Browse files

updated model for task, fixed errors

parent cabce21f
No related branches found
Tags 0.0.1
No related merge requests found
......@@ -19,13 +19,11 @@ pub struct DaemonConfig {
impl DaemonConfig {
pub fn read_config() -> Option<DaemonConfig> {
let path = config_dir()?.join("LibreHomework/daemonconfig.json");
println!("{:?}", path.exists());
if !path.exists() {
println!("Daemon config file not found, creating default config");
DaemonConfig::write_config(default_daemon_config());
}
let config_file = std::fs::read_to_string(path).ok()?;
println!("here");
serde_json::from_str::<HashMap<&str, DaemonConfig>>(&config_file).ok()?.get("daemon").cloned()
}
......
......@@ -3,6 +3,7 @@ use dirs_next::config_dir;
#[derive(Debug)]
pub struct Task {
pub id: u32,
pub name: String,
pub subject: String,
pub description: String,
......@@ -14,6 +15,7 @@ pub struct Database {
impl Database {
pub fn new() -> Option<Self> {
let path = config_dir().unwrap().join("LibreHomework/LibreHomework.db");
if !path.exists() {
return None;
} else {
......@@ -30,20 +32,22 @@ impl Database {
let conn = self.init_connection()?;
let mut stmt = conn.prepare("SELECT * FROM tasks")?;
let mut rows = stmt.query([])?;
println!("what");
while let Some(row) = rows.next()? {
let name = row.get(0)?;
let subject = row.get(1)?;
let description = row.get(2)?;
let expires_at = row.get(3)?;
let id = row.get(0)?;
let name = row.get(1)?;
let subject = row.get(2)?;
let description = row.get(3)?;
let expires_at = row.get(4)?;
tasks.push(Task {
id,
name,
subject,
description,
expires_at
});
println!("pushed")
}
Ok(tasks)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment