From ba5d149a6097c21e6f6020735c10d31ee1f12e5a Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 11 Mar 2021 20:52:30 +0100 Subject: [PATCH] Added docs; started README; started ivago --- Makefile | 7 ++++++- README.md | 2 ++ src/hello/controller.rs | 0 src/hello/mod.rs | 14 +++++++++++--- src/hello/tests.rs | 2 +- src/ivago/controller.rs | 9 +++++++++ src/ivago/mod.rs | 23 ++++++++++++----------- src/main.rs | 14 +++----------- 8 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 src/hello/controller.rs create mode 100644 src/ivago/controller.rs diff --git a/Makefile b/Makefile index 79daa85..ce930eb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ IMAGE := rust_api:latest - shell := /bin/bash @@ -30,3 +29,9 @@ run: test: @ cargo test .PHONY: test + + +# Documentation +docs: + @ cargo doc --no-deps +.PHONY: docs diff --git a/README.md b/README.md index f9a819a..d7dc9e6 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,5 @@ Each module contains the following base files: `controller.rs` becomes its own module folder named `controller`. * `tests.rs`: this contains tests for the specific module. This can also be a module directory if need be. + +Every module has a `routes` function that returns its route macros. diff --git a/src/hello/controller.rs b/src/hello/controller.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/hello/mod.rs b/src/hello/mod.rs index 547276a..c15060b 100644 --- a/src/hello/mod.rs +++ b/src/hello/mod.rs @@ -1,16 +1,24 @@ #[cfg(test)] mod tests; +pub fn routes() -> Vec { + routes![ + world, + hello, + name_age + ] +} + #[get("/world")] -pub fn world() -> &'static str { +fn world() -> &'static str { "Hello, world!" } #[get("/")] -pub fn hello(name: String) -> String { +fn hello(name: String) -> String { format!("Hello, {}", name) } #[get("/world?&")] -pub fn name_age(name: String, age: u16) -> String { +fn name_age(name: String, age: u16) -> String { format!("Hello, {} who is {} years old!", name, age) } diff --git a/src/hello/tests.rs b/src/hello/tests.rs index 83b122d..d4f7096 100644 --- a/src/hello/tests.rs +++ b/src/hello/tests.rs @@ -2,7 +2,7 @@ use rocket::local::Client; use rocket::http::Status; fn rocket() -> rocket::Rocket { - rocket::ignite().mount("/", routes![super::world, super::hello, super::name_age]) + rocket::ignite().mount("/", super::routes()) } #[test] diff --git a/src/ivago/controller.rs b/src/ivago/controller.rs new file mode 100644 index 0000000..8aeef86 --- /dev/null +++ b/src/ivago/controller.rs @@ -0,0 +1,9 @@ +/// Searches the Ivago API for streets in the given city +/// +/// # Arguments +/// +/// * `street` -name of the street +/// * `city` - city the street is in +pub fn search_streets(street: String, city: String) -> Vec { + Vec::new() +} diff --git a/src/ivago/mod.rs b/src/ivago/mod.rs index 12d8ed0..da9f9de 100644 --- a/src/ivago/mod.rs +++ b/src/ivago/mod.rs @@ -1,22 +1,23 @@ #[cfg(test)] mod tests; -// use rocket_contrib::json::Json; -// use rocket::Route; -use http::{Request, Response}; - +mod controller; +use controller as ctrl; pub fn routes() -> Vec { - routes![search_streets] + routes![ + search_streets, + ] } // URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange #[get("/search?")] pub fn search_streets(street: String) -> String { - // Build the request - let mut request = Request::get( - "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets") - .body(()) - .unwrap(); + // // Build the request + // let mut request = Request::get( + // "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets") + // .body(()) + // .unwrap(); - let response = send(request.body(()).unwrap()); + // let response = send(request.body(()).unwrap()); + "".to_string() } diff --git a/src/main.rs b/src/main.rs index b9623f8..43348ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,22 +2,14 @@ #[macro_use] extern crate rocket; +// Route modules mod hello; mod ivago; fn rocket() -> rocket::Rocket { rocket::ignite() - .mount( - "/hello", - routes![ - hello::world, - hello::hello, - hello::name_age - ] - ).mount( - "/ivago", - ivago::routes() - ) + .mount("/hello", hello::routes()) + .mount("/ivago", ivago::routes()) } fn main() {