From 666514c8e2f9767d91acdf64727498bbee2c1d94 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 22 Feb 2021 09:58:01 +0100 Subject: [PATCH] fix the example --- .gitlab-ci.yml | 13 +++++++++++++ example/Cargo.toml | 2 +- example/src/main.rs | 22 +++++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7787130..bc141b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,19 @@ variables: CARGO_HOME: $CI_PROJECT_DIR/cargo RUST_LOG: info,gotham=debug,gotham_restful=trace +check-example: + stage: test + image: rust:slim + before_script: + - cargo -V + script: + - cargo check -p example + cache: + key: cargo-stable-example + paths: + - cargo/ + - target/ + test-default: stage: test image: rust:1.49-slim diff --git a/example/Cargo.toml b/example/Cargo.toml index d049d98..4ddcd5f 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -18,7 +18,7 @@ gitlab = { repository = "msrd0/gotham-restful", branch = "master" } fake = "2.2.2" gotham = { version = "0.5.0", default-features = false } gotham_derive = "0.5.0" -gotham_restful = { version = "0.2.0-dev", features = ["auth", "openapi"], default-features = false } +gotham_restful = { version = "0.2.0-dev", features = ["auth", "cors", "openapi"], default-features = false } log = "0.4.8" pretty_env_logger = "0.4" serde = "1.0.110" diff --git a/example/src/main.rs b/example/src/main.rs index db880d7..d95795c 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -15,11 +15,11 @@ use gotham_restful::{cors::*, *}; use serde::{Deserialize, Serialize}; #[derive(Resource)] -#[resource(read_all, read, search, create, change_all, change, remove, remove_all)] +#[resource(read_all, read, search, create, update_all, update, remove, remove_all)] struct Users {} #[derive(Resource)] -#[resource(ReadAll)] +#[resource(auth_read_all)] struct Auth {} #[derive(Deserialize, OpenapiType, Serialize, StateData, StaticResponseExtender)] @@ -27,7 +27,7 @@ struct User { username: String } -#[read_all(Users)] +#[read_all] fn read_all() -> Success>> { vec![Username().fake(), Username().fake()] .into_iter() @@ -36,7 +36,7 @@ fn read_all() -> Success>> { .into() } -#[read(Users)] +#[read] fn read(id: u64) -> Success { let username: String = Username().fake(); User { @@ -45,17 +45,17 @@ fn read(id: u64) -> Success { .into() } -#[search(Users)] +#[search] fn search(query: User) -> Success { query.into() } -#[create(Users)] +#[create] fn create(body: User) { info!("Created User: {}", body.username); } -#[change_all(Users)] +#[change_all] fn update_all(body: Vec) { info!( "Changing all Users to {:?}", @@ -63,22 +63,22 @@ fn update_all(body: Vec) { ); } -#[change(Users)] +#[change] fn update(id: u64, body: User) { info!("Change User {} to {}", id, body.username); } -#[remove_all(Users)] +#[remove_all] fn remove_all() { info!("Delete all Users"); } -#[remove(Users)] +#[remove] fn remove(id: u64) { info!("Delete User {}", id); } -#[read_all(Auth)] +#[read_all] fn auth_read_all(auth: AuthStatus<()>) -> AuthSuccess { match auth { AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)),