diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 191630a..bc848ea 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +glob = "0.3.1" serde = { version = "1.0.215", features = ["serde_derive"] } serde_json = "1.0.133" toml = "0.8.19" diff --git a/backend/src/files.rs b/backend/src/files.rs index 202b509..e1edfc4 100644 --- a/backend/src/files.rs +++ b/backend/src/files.rs @@ -1,3 +1,4 @@ +use glob::glob; use std::fs::File; use std::io::prelude::*; @@ -14,3 +15,20 @@ pub fn load_file_contents(file_path: String) -> String { } } } + +pub fn list_files(path: String, extension: String) -> Vec { + let mut tmp_path = path.clone(); + let mut files = Vec::::new(); + let glob_path = format!("{}/*.{}", tmp_path, extension); + // tmp_path.push_str(&glob_path); + // println!("{}", glob_path); + + for entry in glob(&glob_path).unwrap() { + match entry { + Ok(p) => files.push(String::from(p.display().to_string())), + Err(e) => return vec![String::new()], + } + } + + return files; +} diff --git a/backend/src/main.rs b/backend/src/main.rs index e4b1102..218b206 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -9,8 +9,17 @@ fn main() { let config = Config::load(); let pool = structs::BingoPool::load_from_file(String::from( - "/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/squares/testdata/testdata.toml", + "/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml", )); + // let pools = BingoPools::load_pools(); + + let files = files::list_files( + String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"), + String::from("toml"), + ); + + println!("{:?}", files); + println!("{}", pool); } diff --git a/backend/src/structs.rs b/backend/src/structs.rs index 3fb8118..e40ccea 100644 --- a/backend/src/structs.rs +++ b/backend/src/structs.rs @@ -58,6 +58,18 @@ impl BingoPool { } } +pub struct BingoPools { + pools: Vec, +} + +impl BingoPools { + pub fn load_pools() -> BingoPools { + BingoPools { + pools: Vec::::new(), + } + } +} + pub struct BingoBoard { size: i64, squares: Vec, diff --git a/backend/workingdir/pools/testdata.toml b/backend/workingdir/pools/testdata.toml new file mode 100644 index 0000000..fa05d6e --- /dev/null +++ b/backend/workingdir/pools/testdata.toml @@ -0,0 +1,18 @@ +[meta] +name = 'Name of pool' +description = 'Description of pool' + +[[squares]] +option = 'First square' + +[[squares]] +option = 'Second square' + +[[squares]] +option = 'Third square' + +[[squares]] +option = 'Fourth square' + +[[squares]] +option = 'Fifth square' diff --git a/backend/workingdir/squares/testdata/testdata.toml b/backend/workingdir/squares/testdata/testdata.toml deleted file mode 100644 index 25cfbde..0000000 --- a/backend/workingdir/squares/testdata/testdata.toml +++ /dev/null @@ -1,12 +0,0 @@ -[meta] -name = 'Test Bingo' -description = 'Because its fucking funny' - -[[squares]] -option = 'Code compiles first try and no one believes you' - -[[squares]] -option = 'There isnt a crate for that already' - -[[squares]] -option = 'Someone tells you to use JS' diff --git a/docs/Super_serious_design_docs.kra b/docs/Super_serious_design_docs.kra new file mode 100644 index 0000000..74b82ec Binary files /dev/null and b/docs/Super_serious_design_docs.kra differ diff --git a/docs/Super_serious_design_docs.png b/docs/Super_serious_design_docs.png new file mode 100644 index 0000000..2a877ed Binary files /dev/null and b/docs/Super_serious_design_docs.png differ