1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 14:57:01 +00:00

add search method

This commit is contained in:
Dominic 2019-10-13 17:43:42 +02:00
parent 8429c425aa
commit 0153b2e22f
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
8 changed files with 84 additions and 13 deletions

View file

@ -16,7 +16,9 @@ gitlab = { repository = "msrd0/gotham-restful", branch = "master" }
[dependencies]
fake = "2.2"
gotham = "0.4"
gotham_derive = "0.4"
gotham_restful = { path = "../gotham_restful", features = ["openapi"] }
hyper = "0.12"
log = "0.4"
log4rs = { version = "0.8", features = ["console_appender"], default-features = false }
serde = "1"

View file

@ -1,3 +1,4 @@
#[macro_use] extern crate gotham_derive;
#[macro_use] extern crate log;
use fake::{faker::internet::en::Username, Fake};
@ -17,20 +18,12 @@ use log4rs::{
use serde::{Deserialize, Serialize};
#[derive(Resource)]
#[rest_resource(ReadAll, Read, Create, DeleteAll, Delete, Update, UpdateAll)]
#[rest_resource(ReadAll, Read, Search, Create, DeleteAll, Delete, Update, UpdateAll)]
struct Users
{
}
// rest_resource!{Users, route => {
// route.read_all::<Self, _>();
// route.read::<Self, _, _>();
// route.create::<Self, _, _>();
// route.update_all::<Self, _, _>();
// route.update::<Self, _, _, _>();
// }}
#[derive(Deserialize, OpenapiType, Serialize)]
#[derive(Deserialize, OpenapiType, Serialize, StateData, StaticResponseExtender)]
struct User
{
username : String
@ -53,6 +46,12 @@ fn read(_state : &mut State, id : u64) -> Success<User>
User { username: format!("{}{}", username, id) }.into()
}
#[rest_search(Users)]
fn search(_state : &mut State, query : User) -> Success<User>
{
query.into()
}
#[rest_create(Users)]
fn create(_state : &mut State, body : User)
{