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:
parent
8429c425aa
commit
0153b2e22f
8 changed files with 84 additions and 13 deletions
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue