1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

fix the example

This commit is contained in:
Dominic 2021-02-22 09:58:01 +01:00
parent 7de11cdae1
commit 666514c8e2
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 25 additions and 12 deletions

View file

@ -8,6 +8,19 @@ variables:
CARGO_HOME: $CI_PROJECT_DIR/cargo CARGO_HOME: $CI_PROJECT_DIR/cargo
RUST_LOG: info,gotham=debug,gotham_restful=trace 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: test-default:
stage: test stage: test
image: rust:1.49-slim image: rust:1.49-slim

View file

@ -18,7 +18,7 @@ gitlab = { repository = "msrd0/gotham-restful", branch = "master" }
fake = "2.2.2" fake = "2.2.2"
gotham = { version = "0.5.0", default-features = false } gotham = { version = "0.5.0", default-features = false }
gotham_derive = "0.5.0" 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" log = "0.4.8"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
serde = "1.0.110" serde = "1.0.110"

View file

@ -15,11 +15,11 @@ use gotham_restful::{cors::*, *};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Resource)] #[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 {} struct Users {}
#[derive(Resource)] #[derive(Resource)]
#[resource(ReadAll)] #[resource(auth_read_all)]
struct Auth {} struct Auth {}
#[derive(Deserialize, OpenapiType, Serialize, StateData, StaticResponseExtender)] #[derive(Deserialize, OpenapiType, Serialize, StateData, StaticResponseExtender)]
@ -27,7 +27,7 @@ struct User {
username: String username: String
} }
#[read_all(Users)] #[read_all]
fn read_all() -> Success<Vec<Option<User>>> { fn read_all() -> Success<Vec<Option<User>>> {
vec![Username().fake(), Username().fake()] vec![Username().fake(), Username().fake()]
.into_iter() .into_iter()
@ -36,7 +36,7 @@ fn read_all() -> Success<Vec<Option<User>>> {
.into() .into()
} }
#[read(Users)] #[read]
fn read(id: u64) -> Success<User> { fn read(id: u64) -> Success<User> {
let username: String = Username().fake(); let username: String = Username().fake();
User { User {
@ -45,17 +45,17 @@ fn read(id: u64) -> Success<User> {
.into() .into()
} }
#[search(Users)] #[search]
fn search(query: User) -> Success<User> { fn search(query: User) -> Success<User> {
query.into() query.into()
} }
#[create(Users)] #[create]
fn create(body: User) { fn create(body: User) {
info!("Created User: {}", body.username); info!("Created User: {}", body.username);
} }
#[change_all(Users)] #[change_all]
fn update_all(body: Vec<User>) { fn update_all(body: Vec<User>) {
info!( info!(
"Changing all Users to {:?}", "Changing all Users to {:?}",
@ -63,22 +63,22 @@ fn update_all(body: Vec<User>) {
); );
} }
#[change(Users)] #[change]
fn update(id: u64, body: User) { fn update(id: u64, body: User) {
info!("Change User {} to {}", id, body.username); info!("Change User {} to {}", id, body.username);
} }
#[remove_all(Users)] #[remove_all]
fn remove_all() { fn remove_all() {
info!("Delete all Users"); info!("Delete all Users");
} }
#[remove(Users)] #[remove]
fn remove(id: u64) { fn remove(id: u64) {
info!("Delete User {}", id); info!("Delete User {}", id);
} }
#[read_all(Auth)] #[read_all]
fn auth_read_all(auth: AuthStatus<()>) -> AuthSuccess<String> { fn auth_read_all(auth: AuthStatus<()>) -> AuthSuccess<String> {
match auth { match auth {
AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)), AuthStatus::Authenticated(data) => Ok(format!("{:?}", data)),