From 889dc4f87b05d838b25428478a8c42dac454a5cf Mon Sep 17 00:00:00 2001
From: fxqnlr <felixquinn03@gmail.com>
Date: Mon, 7 Nov 2022 22:29:35 +0100
Subject: finished rusqlite; added all db tests

---
 src/commands/update.rs | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/commands/update.rs')

diff --git a/src/commands/update.rs b/src/commands/update.rs
index d278a78..e383eae 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -4,7 +4,7 @@ use reqwest::Client;
 
 use futures_util::StreamExt;
 
-use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, get_versions, get_list_version, change_list_versions}, List};
+use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions}, List};
 
 pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
 
@@ -12,7 +12,7 @@ pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
 
     let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?;
 
-    let mut versions = get_versions(config.clone(), mods.clone())?;
+    let mut versions = mods_get_versions(config.clone(), mods.clone())?;
     versions.sort_by_key(|ver| ver.mod_id.clone());
 
     let mut projects = projects(String::from(&config.apis.modrinth), mods).await;
@@ -54,12 +54,15 @@ async fn specific_update(config: Cfg, list: List, project: Project) -> Result<Ve
     }
     
     let mut current: Vec<Version> = vec![];
-    if versions.join("|") != get_list_version(config.clone(), list.clone(), String::from(&project.id))? {
+    if versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))? {
         //get new versions
         print!(" | getting new version");
         let current_str = extract_current_version(applicable_versions.clone())?;
-        current.push(applicable_versions.into_iter().find(|ver| ver.id == current_str).unwrap());
-        change_list_versions(config, list, current_str, versions, project.id)?;
+        let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?;
+        current.push(current_ver.clone());
+
+        let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url;
+        userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?;
     }
 
     if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) };
-- 
cgit v1.2.3