Pass all_titles to add_all_titles as a Vec
This commit is contained in:
parent
0728ba9da8
commit
c53f31d21a
2 changed files with 5 additions and 6 deletions
|
@ -5,10 +5,11 @@
|
||||||
mod crud;
|
mod crud;
|
||||||
mod errors;
|
mod errors;
|
||||||
|
|
||||||
|
use crate::models::InsertTitle;
|
||||||
use errors::DatabaseError;
|
use errors::DatabaseError;
|
||||||
|
|
||||||
/// Insert all titles from Mirabel into the local database
|
/// Insert all titles from Mirabel into the local database
|
||||||
pub fn add_all_titles() -> Result<(), DatabaseError> {
|
pub fn add_all_titles(all_titles: Vec<InsertTitle>) -> Result<(), DatabaseError> {
|
||||||
let connection = &mut crud::establish_connection()?;
|
let connection = &mut crud::establish_connection()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -34,7 +35,6 @@ pub fn sql_example() -> Result<(), DatabaseError> {
|
||||||
vec![Some("fre")],
|
vec![Some("fre")],
|
||||||
vec![],
|
vec![],
|
||||||
Some("https://reseau-mirabel.info/revue/1915"),
|
Some("https://reseau-mirabel.info/revue/1915"),
|
||||||
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("READ:");
|
println!("READ:");
|
||||||
|
|
|
@ -32,17 +32,16 @@ pub fn run() -> Result<(), Box<dyn Error>> {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
let all_titles = &all_titles
|
let all_titles = all_titles
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap() // we just checked for Option above so we can safely unwrap here
|
.unwrap() // we just checked for Option above so we can safely unwrap here
|
||||||
.iter()
|
.iter()
|
||||||
.map(|val| json_to_insert_title(val))
|
.map(|val| json_to_insert_title(val))
|
||||||
.collect::<Vec<InsertTitle>>();
|
.collect::<Vec<InsertTitle>>();
|
||||||
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
|
// 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}");
|
eprintln!("{err}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue