From ea50af892c4268ae06f6df40ee435eadd076228d Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 6 Nov 2022 23:06:54 +0100 Subject: halfswitch to rusqlite; db tests --- src/commands/modification.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index e877a63..7836735 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,6 +1,6 @@ use std::io::{Error, ErrorKind}; -use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{insert_mod, remove_mod_from_list, get_mod_id, insert_mod_in_list, get_mods, get_mods_from_list}, input::Input, get_current_list}; +use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::Input, get_current_list}; pub async fn modification(config: Cfg, args: Option>) -> Result<(), Box> { @@ -40,31 +40,37 @@ async fn add(config: Cfg, args: Vec) -> Result<(), Box = Vec::new(); + for ver in available_versions { + available_versions_vec.push(ver.id); + } //add to current list and mod table - match get_mods_from_list(config.clone(), current_list.clone()) { + match userlist_get_all_ids(config.clone(), current_list.clone().id) { Ok(mods) => { dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } else { - insert_mod_in_list(config.clone(), current_list.clone(), String::from(&project.id), current_version.id, available_versions, file)?; + userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?; } }, - Err(..) => insert_mod_in_list(config.clone(), current_list, String::from(&project.id), current_version.id, available_versions, file)?, + Err(..) => userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?, }; - match get_mods(config.clone()) { + match mods_get_all_ids(config.clone()) { Ok(mods) => { dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) } else { - insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; + mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; } }, - Err(..) => insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?, + Err(..) => { + mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; + }, }; - Ok(()) } @@ -72,11 +78,11 @@ fn remove(config: Cfg, args: Vec) -> Result<(), Box { Err(Box::new(err)) }, + match userlist_remove(config, current_list.id, mod_id) { + Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, Ok(()) => Ok(()), } } -- cgit v1.2.3