diff options
Diffstat (limited to 'src/custom_filters.rs')
-rw-r--r-- | src/custom_filters.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/custom_filters.rs b/src/custom_filters.rs new file mode 100644 index 0000000..86a78d4 --- /dev/null +++ b/src/custom_filters.rs | |||
@@ -0,0 +1,21 @@ | |||
1 | // Common filters ment to be shared between many endpoints | ||
2 | |||
3 | use std::convert::Infallible; | ||
4 | use warp::{Filter, Rejection}; | ||
5 | |||
6 | use crate::schema::{Db, Transaction}; // `Block` coming later | ||
7 | |||
8 | // Database context for routes | ||
9 | pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone { | ||
10 | warp::any().map(move || db.clone()) | ||
11 | } | ||
12 | |||
13 | // Optional query params to allow pagination | ||
14 | // pub fn list_options() -> impl Filter<Extract = (ListOptions,), Error = Rejection> + Clone { | ||
15 | // warp::query::<ListOptions>() | ||
16 | // } | ||
17 | |||
18 | // Accept only JSON body and reject big payloads | ||
19 | pub fn json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone { | ||
20 | warp::body::content_length_limit(1024 * 32).and(warp::body::json()) | ||
21 | } | ||