From 1890d59428dfcca861ea1b7820411d80cc60d713 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 22 Jan 2023 22:34:17 +0100 Subject: Added list version cmd, fixed some todos --- src/db.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 119b2a5..f47bda6 100644 --- a/src/db.rs +++ b/src/db.rs @@ -5,7 +5,7 @@ use rusqlite::Connection; use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; //mods -pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec) -> Result<(), Box> { +pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec) -> MLE<()> { println!("Inserting mod {}({}) into database", name, id); @@ -41,7 +41,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box Result> { +pub fn mods_get_id(config: Cfg, name: String) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -56,12 +56,12 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), + true => Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")), false => Ok(mod_id), } } -pub fn mods_get_name(config: Cfg, id: String) -> Result> { +pub fn mods_get_name(config: Cfg, id: &str) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -76,14 +76,14 @@ pub fn mods_get_name(config: Cfg, id: String) -> Result Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), + true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), false => Ok(mod_name), } } pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> MLE<()> { - println!("Updating versions for {} with \n {}", mod_id, versions); + //println!("Updating versions for {} with \n {}", mod_id, versions); let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -92,7 +92,7 @@ pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> ML Ok(()) } -pub fn mods_remove(config: Cfg, id: String) -> Result<(), Box> { +pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { println!("Removing mod {} from database", id); @@ -131,7 +131,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE) -> MLE, current_link: String) -> Result<(), Box> { +pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_version: String, applicable_versions: Vec, current_link: String) -> MLE<()> { println!("Inserting {} into current list({})", mod_id, list_id); let data = devdir(format!("{}/data.db", config.data).as_str()); @@ -201,7 +201,7 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St }; match version.is_empty() { - true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), + true => Err(MLError::new(ErrorType::DBError, "GAV_MOD_NOT_FOUND")), false => Ok(version), } } @@ -241,7 +241,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String }; match version.is_empty() { - true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), + true => Err(MLError::new(ErrorType::DBError, "GCV_MOD_NOT_FOUND")), false => Ok(version), } } @@ -285,7 +285,7 @@ pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) Ok(versions) } -pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> Result<(), Box> { +pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -322,7 +322,7 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin }; match version.is_empty() { - true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), + true => Err(MLError::new(ErrorType::DBError, "GDV_MOD_NOT_FOUND")), false => Ok(version), } } -- cgit v1.2.3