Add delete endpoints and clean up filters

This commit is contained in:
2020-07-29 00:02:48 -04:00
parent 17cd3f12d2
commit 79b45551fd
7 changed files with 106 additions and 55 deletions

View File

@@ -6,8 +6,37 @@ use super::handlers;
use super::models::{InteriorRefList, ListParams, Owner, Shop};
use super::Environment;
pub fn shops(env: Environment) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path("shops").and(
get_shop(env.clone())
.or(delete_shop(env.clone()))
.or(create_shop(env.clone()))
.or(list_shops(env)),
)
}
pub fn owners(env: Environment) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path("owners").and(
get_owner(env.clone())
.or(delete_owner(env.clone()))
.or(create_owner(env.clone()))
.or(list_owners(env)),
)
}
pub fn interior_ref_lists(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path("interior_ref_lists").and(
get_interior_ref_list(env.clone())
.or(delete_interior_ref_list(env.clone()))
.or(create_interior_ref_list(env.clone()))
.or(list_interior_ref_lists(env)),
)
}
pub fn get_shop(env: Environment) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("shops" / i32)
warp::path::param()
.and(warp::get())
.and(with_env(env))
.and_then(handlers::get_shop)
@@ -16,25 +45,32 @@ pub fn get_shop(env: Environment) -> impl Filter<Extract = impl Reply, Error = R
pub fn create_shop(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("shops")
.and(warp::post())
warp::post()
.and(json_body::<Shop>())
.and(with_env(env))
.and_then(handlers::create_shop)
}
pub fn delete_shop(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path::param()
.and(warp::delete())
.and(with_env(env))
.and_then(handlers::delete_shop)
}
pub fn list_shops(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("shops")
.and(warp::get())
warp::get()
.and(warp::query::<ListParams>())
.and(with_env(env))
.and_then(handlers::list_shops)
}
pub fn get_owner(env: Environment) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("owners" / i32)
warp::path::param()
.and(warp::get())
.and(with_env(env))
.and_then(handlers::get_owner)
@@ -43,19 +79,26 @@ pub fn get_owner(env: Environment) -> impl Filter<Extract = impl Reply, Error =
pub fn create_owner(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("owners")
.and(warp::post())
warp::post()
.and(json_body::<Owner>())
.and(warp::addr::remote())
.and(with_env(env))
.and_then(handlers::create_owner)
}
pub fn delete_owner(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path::param()
.and(warp::delete())
.and(with_env(env))
.and_then(handlers::delete_owner)
}
pub fn list_owners(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("owners")
.and(warp::get())
warp::get()
.and(warp::query::<ListParams>())
.and(with_env(env))
.and_then(handlers::list_owners)
@@ -64,7 +107,7 @@ pub fn list_owners(
pub fn get_interior_ref_list(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_ref_lists" / i32)
warp::path::param()
.and(warp::get())
.and(with_env(env))
.and_then(handlers::get_interior_ref_list)
@@ -73,33 +116,30 @@ pub fn get_interior_ref_list(
pub fn create_interior_ref_list(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_ref_lists")
.and(warp::post())
warp::post()
.and(json_body::<InteriorRefList>())
.and(with_env(env))
.and_then(handlers::create_interior_ref_list)
}
pub fn delete_interior_ref_list(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path::param()
.and(warp::delete())
.and(with_env(env))
.and_then(handlers::delete_interior_ref_list)
}
pub fn list_interior_ref_lists(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_ref_lists")
.and(warp::get())
warp::get()
.and(warp::query::<ListParams>())
.and(with_env(env))
.and_then(handlers::list_interior_ref_lists)
}
pub fn bulk_create_interior_ref_lists(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_ref_lists" / "bulk")
.and(warp::post())
.and(json_body::<Vec<InteriorRefList>>())
.and(with_env(env))
.and_then(handlers::bulk_create_interior_ref_lists)
}
fn with_env(env: Environment) -> impl Filter<Extract = (Environment,), Error = Infallible> + Clone {
warp::any().map(move || env.clone())
}