diff --git a/backend/src/main.rs b/backend/src/main.rs index 218b206..a2ea572 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -8,18 +8,18 @@ use structs::*; fn main() { let config = Config::load(); - let pool = structs::BingoPool::load_from_file(String::from( - "/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml", - )); + // let pool = structs::BingoPool::load_from_file(String::from( + // "/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml", + // )); - // let pools = BingoPools::load_pools(); + let pools = BingoPools::load_pools(); - let files = files::list_files( - String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"), - String::from("toml"), - ); + // let files = files::list_files( + // String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"), + // String::from("toml"), + // ); - println!("{:?}", files); + println!("{}", pools); - println!("{}", pool); + // println!("{}", pool); } diff --git a/backend/src/structs.rs b/backend/src/structs.rs index e40ccea..88cbe84 100644 --- a/backend/src/structs.rs +++ b/backend/src/structs.rs @@ -64,9 +64,35 @@ pub struct BingoPools { impl BingoPools { pub fn load_pools() -> BingoPools { - BingoPools { - pools: Vec::::new(), + let pool_files = files::list_files( + String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"), + String::from("toml"), + ); + let mut pools = Vec::::new(); + for entry in pool_files { + pools.push( + toml::from_str(files::load_file_contents(entry).as_str()) + .expect("Failed to parse file"), + ) } + BingoPools { pools } + } +} + +impl fmt::Display for BingoPools { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Number of pools: {}\n\n", &self.pools.len()).unwrap(); + for entry in &self.pools { + write!( + f, + "Pool: {}\nLength: {}\n\n", + entry.meta.name, + entry.squares.len() + ) + .unwrap(); + } + + write!(f, "") } } diff --git a/backend/workingdir/pools/newdata.toml b/backend/workingdir/pools/newdata.toml new file mode 100644 index 0000000..eddb15f --- /dev/null +++ b/backend/workingdir/pools/newdata.toml @@ -0,0 +1,36 @@ +[meta] +name = 'Test pool 2' +description = 'Description of pool' + +[[squares]] +option = 'First square' + +[[squares]] +option = 'Second square' + +[[squares]] +option = 'Third square' + +[[squares]] +option = 'Fourth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' + +[[squares]] +option = 'Fifth square' diff --git a/backend/workingdir/pools/testdata.toml b/backend/workingdir/pools/testdata.toml index fa05d6e..ac79db8 100644 --- a/backend/workingdir/pools/testdata.toml +++ b/backend/workingdir/pools/testdata.toml @@ -1,5 +1,5 @@ [meta] -name = 'Name of pool' +name = 'Test pool' description = 'Description of pool' [[squares]]