Compare commits

...

5 Commits

8 changed files with 374 additions and 15 deletions

330
Cargo.lock generated
View File

@ -2,12 +2,27 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.21.0" version = "0.21.0"
@ -39,7 +54,13 @@ dependencies = [
"dotenv", "dotenv",
"futures", "futures",
"reqwest", "reqwest",
"serde",
"serde_derive",
"serde_json",
"serde_with",
"tokio", "tokio",
"url",
"uuid",
] ]
[[package]] [[package]]
@ -54,6 +75,29 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
"iana-time-zone",
"num-integer",
"num-traits",
"serde",
"winapi",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
@ -70,6 +114,85 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cxx"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2",
"quote",
"scratch",
"syn",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf"
[[package]]
name = "cxxbridge-macro"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "darling"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]] [[package]]
name = "dotenv" name = "dotenv"
version = "0.15.0" version = "0.15.0"
@ -247,6 +370,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.8" version = "0.2.8"
@ -318,6 +447,36 @@ dependencies = [
"tokio-native-tls", "tokio-native-tls",
] ]
[[package]]
name = "iana-time-zone"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"
@ -336,6 +495,7 @@ checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown", "hashbrown",
"serde",
] ]
[[package]] [[package]]
@ -380,6 +540,15 @@ version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.9" version = "0.4.9"
@ -411,6 +580,16 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.5" version = "0.8.5"
@ -441,6 +620,25 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.15.0" version = "1.15.0"
@ -591,7 +789,7 @@ version = "0.11.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9"
dependencies = [ dependencies = [
"base64", "base64 0.21.0",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
@ -605,6 +803,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"mime", "mime",
"mime_guess",
"native-tls", "native-tls",
"once_cell", "once_cell",
"percent-encoding", "percent-encoding",
@ -643,6 +842,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.8.2" version = "2.8.2"
@ -671,6 +876,20 @@ name = "serde"
version = "1.0.152" version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
@ -695,6 +914,34 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_with"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d904179146de381af4c93d3af6ca4984b3152db687dacb9c3c35e86f39809c"
dependencies = [
"base64 0.13.1",
"chrono",
"hex",
"indexmap",
"serde",
"serde_json",
"serde_with_macros",
"time",
]
[[package]]
name = "serde_with_macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.0" version = "1.4.0"
@ -729,6 +976,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.107" version = "1.0.107"
@ -754,6 +1007,42 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"
@ -856,6 +1145,15 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.10" version = "0.3.10"
@ -877,6 +1175,12 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]] [[package]]
name = "url" name = "url"
version = "2.3.1" version = "2.3.1"
@ -888,12 +1192,27 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "uuid"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.0" version = "0.3.0"
@ -1002,6 +1321,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View File

@ -8,5 +8,13 @@ edition = "2021"
[dependencies] [dependencies]
dotenv = "0.15.0" dotenv = "0.15.0"
futures = "0.3.26" futures = "0.3.26"
reqwest = { version = "0.11.14", features = ["blocking"] }
tokio = { version = "1.25.0", features = ["full"] } tokio = { version = "1.25.0", features = ["full"] }
serde = "^1.0"
serde_derive = "^1.0"
serde_with = "^2.0"
serde_json = "^1.0"
url = "^2.2"
uuid = { version = "^1.0", features = ["serde"] }
[dependencies.reqwest]
version = "^0.11"
features = ["json", "multipart"]

9
src/lib.rs Normal file
View File

@ -0,0 +1,9 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate url;
extern crate reqwest;
pub mod models;

View File

@ -7,6 +7,7 @@ async fn main() {
dotenv().ok(); dotenv().ok();
let api_token = env::var("TANDOOR_TOKEN").expect("Token needed"); let api_token = env::var("TANDOOR_TOKEN").expect("Token needed");
let entries = requester::fetch_shopping_list_entries(&api_token).await; let entries = requester::fetch_shopping_list_entries(&api_token).await;
println!("{:?}",entries)
} }

View File

@ -24,7 +24,7 @@ pub struct IngredientFood {
#[serde(rename = "recipe", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] #[serde(rename = "recipe", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub recipe: Option<Option<Box<crate::models::FoodRecipe>>>, pub recipe: Option<Option<Box<crate::models::FoodRecipe>>>,
#[serde(rename = "food_onhand", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] #[serde(rename = "food_onhand", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub food_onhand: Option<Option<String>>, pub food_onhand: Option<Option<bool>>,
#[serde(rename = "supermarket_category", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] #[serde(rename = "supermarket_category", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub supermarket_category: Option<Option<Box<crate::models::FoodSupermarketCategory>>>, pub supermarket_category: Option<Option<Box<crate::models::FoodSupermarketCategory>>>,
#[serde(rename = "parent", skip_serializing_if = "Option::is_none")] #[serde(rename = "parent", skip_serializing_if = "Option::is_none")]
@ -44,7 +44,7 @@ pub struct IngredientFood {
#[serde(rename = "substitute_children", skip_serializing_if = "Option::is_none")] #[serde(rename = "substitute_children", skip_serializing_if = "Option::is_none")]
pub substitute_children: Option<bool>, pub substitute_children: Option<bool>,
#[serde(rename = "substitute_onhand", skip_serializing_if = "Option::is_none")] #[serde(rename = "substitute_onhand", skip_serializing_if = "Option::is_none")]
pub substitute_onhand: Option<String>, pub substitute_onhand: Option<bool>,
#[serde(rename = "child_inherit_fields", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] #[serde(rename = "child_inherit_fields", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub child_inherit_fields: Option<Option<Vec<crate::models::FoodInheritFieldsInner>>>, pub child_inherit_fields: Option<Option<Vec<crate::models::FoodInheritFieldsInner>>>,
} }

View File

@ -24,13 +24,13 @@ pub struct ShoppingListEntriesInnerRecipeMealplan {
#[serde(rename = "mealplan", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] #[serde(rename = "mealplan", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub mealplan: Option<Option<i32>>, pub mealplan: Option<Option<i32>>,
#[serde(rename = "servings")] #[serde(rename = "servings")]
pub servings: String, pub servings: f32,
#[serde(rename = "mealplan_note", skip_serializing_if = "Option::is_none")] #[serde(rename = "mealplan_note", skip_serializing_if = "Option::is_none")]
pub mealplan_note: Option<String>, pub mealplan_note: Option<String>,
} }
impl ShoppingListEntriesInnerRecipeMealplan { impl ShoppingListEntriesInnerRecipeMealplan {
pub fn new(servings: String) -> ShoppingListEntriesInnerRecipeMealplan { pub fn new(servings: f32) -> ShoppingListEntriesInnerRecipeMealplan {
ShoppingListEntriesInnerRecipeMealplan { ShoppingListEntriesInnerRecipeMealplan {
id: None, id: None,
recipe_name: None, recipe_name: None,

View File

@ -26,7 +26,7 @@ pub struct ShoppingListEntry {
#[serde(rename = "ingredient_note", skip_serializing_if = "Option::is_none")] #[serde(rename = "ingredient_note", skip_serializing_if = "Option::is_none")]
pub ingredient_note: Option<String>, pub ingredient_note: Option<String>,
#[serde(rename = "amount")] #[serde(rename = "amount")]
pub amount: String, pub amount: f32,
#[serde(rename = "order", skip_serializing_if = "Option::is_none")] #[serde(rename = "order", skip_serializing_if = "Option::is_none")]
pub order: Option<i32>, pub order: Option<i32>,
#[serde(rename = "checked", skip_serializing_if = "Option::is_none")] #[serde(rename = "checked", skip_serializing_if = "Option::is_none")]
@ -44,7 +44,7 @@ pub struct ShoppingListEntry {
} }
impl ShoppingListEntry { impl ShoppingListEntry {
pub fn new(food: Option<crate::models::IngredientFood>, amount: String) -> ShoppingListEntry { pub fn new(food: Option<crate::models::IngredientFood>, amount: f32) -> ShoppingListEntry {
ShoppingListEntry { ShoppingListEntry {
id: None, id: None,
list_recipe: None, list_recipe: None,

View File

@ -1,6 +1,9 @@
use cart_sync::models::{shopping_list_entry, ShoppingListEntry};
use reqwest::{self, Client}; use reqwest::{self, Client};
use serde::Deserialize;
use std::env; use std::env;
pub async fn fetch_shopping_list_entries(api_token: &str) {
pub async fn fetch_shopping_list_entries(api_token: &str) -> Option<Vec<ShoppingListEntry>> {
let base_url = env::var("TANDOOR_BASE_URL").expect("Base Url needed"); let base_url = env::var("TANDOOR_BASE_URL").expect("Base Url needed");
let route = "/shopping-list-entry/"; let route = "/shopping-list-entry/";
@ -10,22 +13,32 @@ pub async fn fetch_shopping_list_entries(api_token: &str) {
.get(&url) .get(&url)
.query(&[("checked", "false")]) .query(&[("checked", "false")])
.bearer_auth(api_token); .bearer_auth(api_token);
match req.send().await { let response = req.send().await;
match response {
Ok(resolved) => match resolved.status() { Ok(resolved) => match resolved.status() {
reqwest::StatusCode::OK => { reqwest::StatusCode::OK => {
//println!("Success {:#?}", resolved);
println!("{}", resolved.text().await.unwrap()); let json_body = resolved.json::<Vec<ShoppingListEntry>>().await;
println!("Watch me") match json_body {
Ok(j) => Some(j),
Err(e) => {
println!("{}", e);
None
}
}
} }
reqwest::StatusCode::FORBIDDEN => { reqwest::StatusCode::FORBIDDEN => {
println!("Denied {:#?}", resolved) println!("Denied {:#?}", resolved);
None
} }
_ => { _ => {
println!("Fail {:#?}", resolved); println!("Fail {:#?}", resolved);
None
} }
}, },
Err(failed) => { Err(failed) => {
println!("There was an error in the reqwest: {failed}") println!("There was an error in the reqwest: {failed}");
None
} }
} }
} }