diff --git a/Cargo.lock b/Cargo.lock index 6392ceb..24996a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,17 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +[[package]] +name = "api" +version = "0.1.0" +dependencies = [ + "axum 0.7.5", + "dotenv", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "app_dirs2" version = "2.5.5" @@ -213,7 +224,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -245,7 +256,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -287,15 +298,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "axum-macros", "bitflags 1.3.2", "bytes", "futures-util", "headers", - "http", - "http-body", - "hyper", + "http 0.2.9", + "http-body 0.4.5", + "hyper 0.14.27", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core 0.4.3", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-util", "itoa", "matchit", "memchr", @@ -307,11 +351,12 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -323,12 +368,33 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.9", + "http-body 0.4.5", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", "mime", + "pin-project-lite", "rustversion", + "sync_wrapper 0.1.2", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -337,13 +403,13 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a93e433be9382c737320af3924f7d5fc6f89c155cf2bf88949d8f5126fab283f" dependencies = [ - "axum", - "axum-core", + "axum 0.6.20", + "axum-core 0.3.4", "bytes", "cookie", "futures-util", - "http", - "http-body", + "http 0.2.9", + "http-body 0.4.5", "mime", "pin-project-lite", "serde", @@ -359,7 +425,7 @@ version = "0.6.0" source = "git+https://github.com/maxcountryman/axum-login?rev=5239b38b2698a3db3f92075b6ad430aea79c215a#5239b38b2698a3db3f92075b6ad430aea79c215a" dependencies = [ "async-trait", - "axum", + "axum 0.6.20", "axum-sessions", "base64 0.21.5", "dyn-clone", @@ -385,7 +451,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -395,10 +461,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "714cad544cd87d8da821cda715bb9aaa5d4d1adbdb64c549b18138e3cbf93c44" dependencies = [ "async-session", - "axum", + "axum 0.6.20", "axum-extra", "futures", - "http-body", + "http-body 0.4.5", "tokio", "tower", "tracing", @@ -408,7 +474,7 @@ dependencies = [ name = "backend" version = "0.1.0" dependencies = [ - "axum", + "axum 0.6.20", "axum-login", "bigdecimal", "chrono", @@ -635,7 +701,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -799,7 +865,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -1674,7 +1740,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -1807,7 +1873,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -2331,7 +2397,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.9", "indexmap 1.9.3", "slab", "tokio", @@ -2373,7 +2439,7 @@ dependencies = [ "base64 0.21.5", "bytes", "headers-core", - "http", + "http 0.2.9", "httpdate", "mime", "sha1", @@ -2385,7 +2451,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" dependencies = [ - "http", + "http 0.2.9", ] [[package]] @@ -2490,6 +2556,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.5" @@ -2497,7 +2574,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.9", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -2545,8 +2645,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.9", + "http-body 0.4.5", "httparse", "httpdate", "itoa", @@ -2558,6 +2658,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -2565,12 +2684,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.27", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.3.1", + "pin-project-lite", + "socket2 0.5.5", + "tokio", +] + [[package]] name = "iana-time-zone" version = "0.1.58" @@ -3124,8 +3259,8 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0bab19cef8a7fe1c18a43e881793bfc9d4ea984befec3ae5bd0415abf3ecf00" dependencies = [ - "axum-core", - "http", + "axum-core 0.3.4", + "http 0.2.9", "itoa", "maud_macros", ] @@ -3240,7 +3375,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -3752,7 +3887,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -3961,7 +4096,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -4015,7 +4150,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -4044,7 +4179,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -4153,9 +4288,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -4188,9 +4323,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -4371,9 +4506,9 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", - "hyper", + "http 0.2.9", + "http-body 0.4.5", + "hyper 0.14.27", "hyper-tls", "ipnet", "js-sys", @@ -4452,7 +4587,7 @@ version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1e7d90385b59f0a6bf3d3b757f3ca4ece2048265d70db20a2016043d4509a40" dependencies = [ - "axum", + "axum 0.6.20", "rust-embed-impl", "rust-embed-utils", "walkdir", @@ -4467,7 +4602,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.39", + "syn 2.0.61", "walkdir", ] @@ -4643,29 +4778,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -4836,9 +4971,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smithay-client-toolkit" @@ -5229,9 +5364,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" dependencies = [ "proc-macro2", "quote", @@ -5244,6 +5379,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "system-configuration" version = "0.5.1" @@ -5674,7 +5815,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -5769,6 +5910,7 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2 0.5.5", @@ -5784,7 +5926,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -5892,8 +6034,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.9", + "http-body 0.4.5", "http-range-header", "httpdate", "mime", @@ -5939,7 +6081,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] @@ -6201,7 +6343,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", "wasm-bindgen-shared", ] @@ -6235,7 +6377,7 @@ checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6937,7 +7079,7 @@ checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.61", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f93bba6..4c85f6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["app", "metro-scrape", "backend", "foodlib", "cli-client"] +members = ["app", "metro-scrape", "backend", "foodlib", "cli-client", "api" ] default-members = ["app", "backend", "foodlib"] [workspace.dependencies] diff --git a/api/Cargo.toml b/api/Cargo.toml new file mode 100644 index 0000000..42c0989 --- /dev/null +++ b/api/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "api" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axum = "0.7.5" +dotenv.workspace = true +serde = { workspace = true, features = ["derive"] } +serde_json = "1.0.117" +tokio = { workspace = true, features = ["full"] } diff --git a/api/src/events.rs b/api/src/events.rs new file mode 100644 index 0000000..278b002 --- /dev/null +++ b/api/src/events.rs @@ -0,0 +1,41 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router}; + +pub fn router() -> Router { + Router::new() + .route("/", get(list)) + .route("/", post(update_event)) + .route("/:event_id/", get(show_event)) + .route("/:event_id/", delete(delete_event)) + .route("/:event_id/", post(update_event)) + .route("/:event_id/meals/", put(meal_add)) + .route("/:event_id/meals/", delete(meal_delete)) + .route("/:event_id/meals/", post(meal_update)) +} + +async fn list() -> impl IntoResponse { + StatusCode::OK +} + +async fn show_event() -> impl IntoResponse { + StatusCode::OK +} + +async fn delete_event() -> impl IntoResponse { + StatusCode::OK +} + +async fn update_event() -> impl IntoResponse { + StatusCode::OK +} + +async fn meal_add() -> impl IntoResponse { + StatusCode::OK +} + +async fn meal_delete() -> impl IntoResponse { + StatusCode::OK +} + +async fn meal_update() -> impl IntoResponse { + StatusCode::OK +} diff --git a/api/src/ingredients.rs b/api/src/ingredients.rs new file mode 100644 index 0000000..e268929 --- /dev/null +++ b/api/src/ingredients.rs @@ -0,0 +1,26 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router}; + +pub fn router() -> Router { + Router::new() + .route("/", get(list)) + .route("/", put(add)) + .route("/:ingredient_id/", get(show_ingredient)) + .route("/:ingredient_id/", delete(delete_ingredient)) + .route("/:ingredient_id/", post(show_ingredient)) +} + +async fn add() -> impl IntoResponse { + StatusCode::OK +} + +async fn list() -> impl IntoResponse { + StatusCode::OK +} + +async fn show_ingredient() -> impl IntoResponse { + StatusCode::OK +} + +async fn delete_ingredient() -> impl IntoResponse { + StatusCode::OK +} diff --git a/api/src/main.rs b/api/src/main.rs new file mode 100644 index 0000000..b40977c --- /dev/null +++ b/api/src/main.rs @@ -0,0 +1,23 @@ +use axum::Router; +use tokio::net::TcpListener; + +mod events; +mod ingredients; +mod places; +mod reciepes; + +#[tokio::main] +async fn main() { + let app = Router::new() + .nest("/events", events::router()) + .nest("/ingredients", ingredients::router()) + .nest("/places", places::router()) + .nest("/reciepes", reciepes::router()); + + println!("Server started successfully at 0.0.0.0:8080"); + + let listener = TcpListener::bind("0.0.0.0:8080").await.unwrap(); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); +} diff --git a/api/src/places.rs b/api/src/places.rs new file mode 100644 index 0000000..bc65944 --- /dev/null +++ b/api/src/places.rs @@ -0,0 +1,30 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router}; + +pub fn router() -> Router { + Router::new() + .route("/", get(list_places)) + .route("/", put(add_places)) + .route("/:place_id", get(get_place)) + .route("/:place_id", post(update_place)) + .route("/:place_id", delete(delete_place)) +} + +async fn list_places() -> impl IntoResponse { + StatusCode::OK +} + +async fn add_places() -> impl IntoResponse { + StatusCode::OK +} + +async fn get_place() -> impl IntoResponse { + StatusCode::OK +} + +async fn update_place() -> impl IntoResponse { + StatusCode::OK +} + +async fn delete_place() -> impl IntoResponse { + StatusCode::OK +} diff --git a/api/src/reciepes.rs b/api/src/reciepes.rs new file mode 100644 index 0000000..e926eb3 --- /dev/null +++ b/api/src/reciepes.rs @@ -0,0 +1,30 @@ +use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router}; + +pub fn router() -> Router { + Router::new() + .route("/", get(list_reciepes)) + .route("/", put(add_reciepe)) + .route("/:recipe_id/", get(calc_reciepe)) + .route("/:recipe_id/", post(update_reciepe)) + .route("/:recipe_id/", delete(update_reciepe)) + .route("/:recipe_id/steps/", get(update_reciepe)) + .route("/:recipe_id/steps/", post(update_reciepe)) + .route("/:recipe_id/ingredients/", get(calc_reciepe)) + .route("/:recipe_id/ingredients/", post(calc_reciepe)) +} + +async fn list_reciepes() -> impl IntoResponse { + StatusCode::OK +} + +async fn add_reciepe() -> impl IntoResponse { + StatusCode::OK +} + +async fn calc_reciepe() -> impl IntoResponse { + StatusCode::OK +} + +async fn update_reciepe() -> impl IntoResponse { + StatusCode::OK +}