diff --git a/src/database.rs b/src/database.rs index 465451f..b7327e9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -5,10 +5,11 @@ mod crud; mod errors; +use crate::models::InsertTitle; use errors::DatabaseError; /// Insert all titles from Mirabel into the local database -pub fn add_all_titles() -> Result<(), DatabaseError> { +pub fn add_all_titles(all_titles: Vec) -> Result<(), DatabaseError> { let connection = &mut crud::establish_connection()?; Ok(()) @@ -34,7 +35,6 @@ pub fn sql_example() -> Result<(), DatabaseError> { vec![Some("fre")], vec![], Some("https://reseau-mirabel.info/revue/1915"), - )?; println!("READ:"); diff --git a/src/lib.rs b/src/lib.rs index 7a5528a..3bc48bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,17 +32,16 @@ pub fn run() -> Result<(), Box> { process::exit(1); }); - let all_titles = &all_titles + let all_titles = all_titles .as_array() .unwrap() // we just checked for Option above so we can safely unwrap here .iter() .map(|val| json_to_insert_title(val)) .collect::>(); - dbg!(&all_titles); - // TODO: don't collect all_titles and pass the iterator to database::add_all_titles + // TODO: don't collect all_titles and pass the iterator to database::add_all_titles // Add the fetched titles to the database - database::add_all_titles().unwrap_or_else(|err| { + database::add_all_titles(all_titles).unwrap_or_else(|err| { eprintln!("{err}"); process::exit(1); });