mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 14:57:01 +00:00
rename update to change, delete to remove, and remove rest_ prefix from macros
This commit is contained in:
parent
3de130e104
commit
cc86d3396c
8 changed files with 85 additions and 88 deletions
|
@ -175,10 +175,10 @@ pub use resource::{
|
|||
ResourceRead,
|
||||
ResourceSearch,
|
||||
ResourceCreate,
|
||||
ResourceUpdateAll,
|
||||
ResourceUpdate,
|
||||
ResourceDeleteAll,
|
||||
ResourceDelete
|
||||
ResourceChangeAll,
|
||||
ResourceChange,
|
||||
ResourceRemoveAll,
|
||||
ResourceRemove
|
||||
};
|
||||
|
||||
mod response;
|
||||
|
|
|
@ -106,7 +106,7 @@ macro_rules! implOpenapiRouter {
|
|||
(&mut *(self.0).router, self.1).create::<Handler>()
|
||||
}
|
||||
|
||||
fn update_all<Handler : ResourceUpdateAll>(&mut self)
|
||||
fn change_all<Handler : ResourceChangeAll>(&mut self)
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static
|
||||
|
@ -119,10 +119,10 @@ macro_rules! implOpenapiRouter {
|
|||
item.put = Some(OperationDescription::new::<Handler>(schema).with_body::<Handler::Body>(body_schema).into_operation());
|
||||
(self.0).openapi_builder.add_path(path, item);
|
||||
|
||||
(&mut *(self.0).router, self.1).update_all::<Handler>()
|
||||
(&mut *(self.0).router, self.1).change_all::<Handler>()
|
||||
}
|
||||
|
||||
fn update<Handler : ResourceUpdate>(&mut self)
|
||||
fn change<Handler : ResourceChange>(&mut self)
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static
|
||||
|
@ -136,10 +136,10 @@ macro_rules! implOpenapiRouter {
|
|||
item.put = Some(OperationDescription::new::<Handler>(schema).add_path_param("id", id_schema).with_body::<Handler::Body>(body_schema).into_operation());
|
||||
(self.0).openapi_builder.add_path(path, item);
|
||||
|
||||
(&mut *(self.0).router, self.1).update::<Handler>()
|
||||
(&mut *(self.0).router, self.1).change::<Handler>()
|
||||
}
|
||||
|
||||
fn delete_all<Handler : ResourceDeleteAll>(&mut self)
|
||||
fn remove_all<Handler : ResourceRemoveAll>(&mut self)
|
||||
{
|
||||
let schema = (self.0).openapi_builder.add_schema::<Handler::Res>();
|
||||
|
||||
|
@ -148,10 +148,10 @@ macro_rules! implOpenapiRouter {
|
|||
item.delete = Some(OperationDescription::new::<Handler>(schema).into_operation());
|
||||
(self.0).openapi_builder.add_path(path, item);
|
||||
|
||||
(&mut *(self.0).router, self.1).delete_all::<Handler>()
|
||||
(&mut *(self.0).router, self.1).remove_all::<Handler>()
|
||||
}
|
||||
|
||||
fn delete<Handler : ResourceDelete>(&mut self)
|
||||
fn remove<Handler : ResourceRemove>(&mut self)
|
||||
{
|
||||
let schema = (self.0).openapi_builder.add_schema::<Handler::Res>();
|
||||
let id_schema = (self.0).openapi_builder.add_schema::<Handler::ID>();
|
||||
|
@ -161,7 +161,7 @@ macro_rules! implOpenapiRouter {
|
|||
item.delete = Some(OperationDescription::new::<Handler>(schema).add_path_param("id", id_schema).into_operation());
|
||||
(self.0).openapi_builder.add_path(path, item);
|
||||
|
||||
(&mut *(self.0).router, self.1).delete::<Handler>()
|
||||
(&mut *(self.0).router, self.1).remove::<Handler>()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,32 +68,32 @@ pub trait ResourceCreate : ResourceMethod
|
|||
}
|
||||
|
||||
/// Handle a PUT request on the Resource root.
|
||||
pub trait ResourceUpdateAll : ResourceMethod
|
||||
pub trait ResourceChangeAll : ResourceMethod
|
||||
{
|
||||
type Body : RequestBody;
|
||||
|
||||
fn update_all(state : State, body : Self::Body) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
fn change_all(state : State, body : Self::Body) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
}
|
||||
|
||||
/// Handle a PUT request on the Resource with an id.
|
||||
pub trait ResourceUpdate : ResourceMethod
|
||||
pub trait ResourceChange : ResourceMethod
|
||||
{
|
||||
type Body : RequestBody;
|
||||
type ID : ResourceID + 'static;
|
||||
|
||||
fn update(state : State, id : Self::ID, body : Self::Body) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
fn change(state : State, id : Self::ID, body : Self::Body) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
}
|
||||
|
||||
/// Handle a DELETE request on the Resource root.
|
||||
pub trait ResourceDeleteAll : ResourceMethod
|
||||
pub trait ResourceRemoveAll : ResourceMethod
|
||||
{
|
||||
fn delete_all(state : State) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
fn remove_all(state : State) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
}
|
||||
|
||||
/// Handle a DELETE request on the Resource with an id.
|
||||
pub trait ResourceDelete : ResourceMethod
|
||||
pub trait ResourceRemove : ResourceMethod
|
||||
{
|
||||
type ID : ResourceID + 'static;
|
||||
|
||||
fn delete(state : State, id : Self::ID) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
fn remove(state : State, id : Self::ID) -> Pin<Box<dyn Future<Output = (State, Self::Res)> + Send>>;
|
||||
}
|
||||
|
|
|
@ -78,19 +78,19 @@ pub trait DrawResourceRoutes
|
|||
Handler::Res : 'static,
|
||||
Handler::Body : 'static;
|
||||
|
||||
fn update_all<Handler : ResourceUpdateAll>(&mut self)
|
||||
fn change_all<Handler : ResourceChangeAll>(&mut self)
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static;
|
||||
|
||||
fn update<Handler : ResourceUpdate>(&mut self)
|
||||
fn change<Handler : ResourceChange>(&mut self)
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static;
|
||||
|
||||
fn delete_all<Handler : ResourceDeleteAll>(&mut self);
|
||||
fn remove_all<Handler : ResourceRemoveAll>(&mut self);
|
||||
|
||||
fn delete<Handler : ResourceDelete>(&mut self);
|
||||
fn remove<Handler : ResourceRemove>(&mut self);
|
||||
}
|
||||
|
||||
fn response_from(res : Response, state : &State) -> gotham::hyper::Response<Body>
|
||||
|
@ -217,15 +217,15 @@ where
|
|||
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::create(state, body))
|
||||
}
|
||||
|
||||
fn update_all_handler<Handler : ResourceUpdateAll>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
fn change_all_handler<Handler : ResourceChangeAll>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static
|
||||
{
|
||||
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::update_all(state, body))
|
||||
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::change_all(state, body))
|
||||
}
|
||||
|
||||
fn update_handler<Handler : ResourceUpdate>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
fn change_handler<Handler : ResourceChange>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
where
|
||||
Handler::Res : 'static,
|
||||
Handler::Body : 'static
|
||||
|
@ -234,21 +234,21 @@ where
|
|||
let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state);
|
||||
path.id.clone()
|
||||
};
|
||||
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::update(state, id, body))
|
||||
handle_with_body::<Handler::Body, _, _>(state, |state, body| Handler::change(state, id, body))
|
||||
}
|
||||
|
||||
fn delete_all_handler<Handler : ResourceDeleteAll>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
fn remove_all_handler<Handler : ResourceRemoveAll>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
{
|
||||
to_handler_future(state, |state| Handler::delete_all(state)).boxed()
|
||||
to_handler_future(state, |state| Handler::remove_all(state)).boxed()
|
||||
}
|
||||
|
||||
fn delete_handler<Handler : ResourceDelete>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
fn remove_handler<Handler : ResourceRemove>(state : State) -> Pin<Box<HandlerFuture>>
|
||||
{
|
||||
let id = {
|
||||
let path : &PathExtractor<Handler::ID> = PathExtractor::borrow_from(&state);
|
||||
path.id.clone()
|
||||
};
|
||||
to_handler_future(state, |state| Handler::delete(state, id)).boxed()
|
||||
to_handler_future(state, |state| Handler::remove(state, id)).boxed()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -386,7 +386,7 @@ macro_rules! implDrawResourceRoutes {
|
|||
.to(|state| create_handler::<Handler>(state));
|
||||
}
|
||||
|
||||
fn update_all<Handler : ResourceUpdateAll>(&mut self)
|
||||
fn change_all<Handler : ResourceChangeAll>(&mut self)
|
||||
where
|
||||
Handler::Res : Send + 'static,
|
||||
Handler::Body : 'static
|
||||
|
@ -396,10 +396,10 @@ macro_rules! implDrawResourceRoutes {
|
|||
self.0.put(&self.1)
|
||||
.extend_route_matcher(accept_matcher)
|
||||
.extend_route_matcher(content_matcher)
|
||||
.to(|state| update_all_handler::<Handler>(state));
|
||||
.to(|state| change_all_handler::<Handler>(state));
|
||||
}
|
||||
|
||||
fn update<Handler : ResourceUpdate>(&mut self)
|
||||
fn change<Handler : ResourceChange>(&mut self)
|
||||
where
|
||||
Handler::Res : Send + 'static,
|
||||
Handler::Body : 'static
|
||||
|
@ -410,24 +410,24 @@ macro_rules! implDrawResourceRoutes {
|
|||
.extend_route_matcher(accept_matcher)
|
||||
.extend_route_matcher(content_matcher)
|
||||
.with_path_extractor::<PathExtractor<Handler::ID>>()
|
||||
.to(|state| update_handler::<Handler>(state));
|
||||
.to(|state| change_handler::<Handler>(state));
|
||||
}
|
||||
|
||||
fn delete_all<Handler : ResourceDeleteAll>(&mut self)
|
||||
fn remove_all<Handler : ResourceRemoveAll>(&mut self)
|
||||
{
|
||||
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
|
||||
self.0.delete(&self.1)
|
||||
.extend_route_matcher(matcher)
|
||||
.to(|state| delete_all_handler::<Handler>(state));
|
||||
.to(|state| remove_all_handler::<Handler>(state));
|
||||
}
|
||||
|
||||
fn delete<Handler : ResourceDelete>(&mut self)
|
||||
fn remove<Handler : ResourceRemove>(&mut self)
|
||||
{
|
||||
let matcher : MaybeMatchAcceptHeader = Handler::Res::accepted_types().into();
|
||||
self.0.delete(&format!("{}/:id", self.1))
|
||||
.extend_route_matcher(matcher)
|
||||
.with_path_extractor::<PathExtractor<Handler::ID>>()
|
||||
.to(|state| delete_handler::<Handler>(state));
|
||||
.to(|state| remove_handler::<Handler>(state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue