mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-22 12:42:28 +00:00
fix the example
This commit is contained in:
parent
7de11cdae1
commit
666514c8e2
3 changed files with 25 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<Option<User>>> {
|
||||
vec![Username().fake(), Username().fake()]
|
||||
.into_iter()
|
||||
|
@ -36,7 +36,7 @@ fn read_all() -> Success<Vec<Option<User>>> {
|
|||
.into()
|
||||
}
|
||||
|
||||
#[read(Users)]
|
||||
#[read]
|
||||
fn read(id: u64) -> Success<User> {
|
||||
let username: String = Username().fake();
|
||||
User {
|
||||
|
@ -45,17 +45,17 @@ fn read(id: u64) -> Success<User> {
|
|||
.into()
|
||||
}
|
||||
|
||||
#[search(Users)]
|
||||
#[search]
|
||||
fn search(query: User) -> Success<User> {
|
||||
query.into()
|
||||
}
|
||||
|
||||
#[create(Users)]
|
||||
#[create]
|
||||
fn create(body: User) {
|
||||
info!("Created User: {}", body.username);
|
||||
}
|
||||
|
||||
#[change_all(Users)]
|
||||
#[change_all]
|
||||
fn update_all(body: Vec<User>) {
|
||||
info!(
|
||||
"Changing all Users to {:?}",
|
||||
|
@ -63,22 +63,22 @@ fn update_all(body: Vec<User>) {
|
|||
);
|
||||
}
|
||||
|
||||
#[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<String> {
|
||||
match auth {
|
||||
AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)),
|
||||
|
|
Loading…
Add table
Reference in a new issue