diff options
author | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
commit | ea50af892c4268ae06f6df40ee435eadd076228d (patch) | |
tree | dce2f1fed88f168552b8069d22d9176d7dd2879d /src/commands/modification.rs | |
parent | c33b8be79e8cfac9e2fa76c1f63c85e020cdf4a0 (diff) | |
download | modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar.gz modlist-ea50af892c4268ae06f6df40ee435eadd076228d.zip |
halfswitch to rusqlite; db tests
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 28 |
1 files changed, 17 insertions, 11 deletions
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 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | 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}; | 3 | 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}; |
4 | 4 | ||
5 | pub async fn modification(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn modification(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -40,31 +40,37 @@ async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::E | |||
40 | let current_version = available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap(); | 40 | let current_version = available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap(); |
41 | 41 | ||
42 | let file = current_version.files.into_iter().find(|f| f.primary).unwrap().url; | 42 | let file = current_version.files.into_iter().find(|f| f.primary).unwrap().url; |
43 | |||
44 | let mut available_versions_vec: Vec<String> = Vec::new(); | ||
45 | for ver in available_versions { | ||
46 | available_versions_vec.push(ver.id); | ||
47 | } | ||
43 | //add to current list and mod table | 48 | //add to current list and mod table |
44 | match get_mods_from_list(config.clone(), current_list.clone()) { | 49 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { |
45 | Ok(mods) => { | 50 | Ok(mods) => { |
46 | dbg!(&mods); | 51 | dbg!(&mods); |
47 | if mods.contains(&project.id) { | 52 | if mods.contains(&project.id) { |
48 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 53 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
49 | else { | 54 | else { |
50 | insert_mod_in_list(config.clone(), current_list.clone(), String::from(&project.id), current_version.id, available_versions, file)?; | 55 | userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?; |
51 | } | 56 | } |
52 | }, | 57 | }, |
53 | Err(..) => insert_mod_in_list(config.clone(), current_list, String::from(&project.id), current_version.id, available_versions, file)?, | 58 | Err(..) => userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?, |
54 | }; | 59 | }; |
55 | 60 | ||
56 | match get_mods(config.clone()) { | 61 | match mods_get_all_ids(config.clone()) { |
57 | Ok(mods) => { | 62 | Ok(mods) => { |
58 | dbg!(&mods); | 63 | dbg!(&mods); |
59 | if mods.contains(&project.id) { | 64 | if mods.contains(&project.id) { |
60 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) | 65 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) |
61 | } else { | 66 | } else { |
62 | insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | 67 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; |
63 | } | 68 | } |
64 | }, | 69 | }, |
65 | Err(..) => insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?, | 70 | Err(..) => { |
71 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | ||
72 | }, | ||
66 | }; | 73 | }; |
67 | |||
68 | Ok(()) | 74 | Ok(()) |
69 | } | 75 | } |
70 | 76 | ||
@@ -72,11 +78,11 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
72 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; | 78 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; |
73 | 79 | ||
74 | let current_list = get_current_list(config.clone())?; | 80 | let current_list = get_current_list(config.clone())?; |
75 | let mod_id = get_mod_id(config.clone(), String::from(&args[0]))?; | 81 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; |
76 | 82 | ||
77 | //TODO implement remove from modlist if not in any other lists && config clean is true | 83 | //TODO implement remove from modlist if not in any other lists && config clean is true |
78 | match remove_mod_from_list(config, current_list, mod_id) { | 84 | match userlist_remove(config, current_list.id, mod_id) { |
79 | Err(err) => { Err(Box::new(err)) }, | 85 | Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, |
80 | Ok(()) => Ok(()), | 86 | Ok(()) => Ok(()), |
81 | } | 87 | } |
82 | } | 88 | } |