diff options
| author | Yigit Sever | 2021-04-07 01:08:31 +0300 |
|---|---|---|
| committer | Yigit Sever | 2021-04-07 01:08:31 +0300 |
| commit | c3ba5ad5ebe1d5bb28ed0a340af93e8547b1c5bc (patch) | |
| tree | 43345c12a7caf4c94532a7b54638e756af10b3af /src/custom_filters.rs | |
| download | gradecoin-c3ba5ad5ebe1d5bb28ed0a340af93e8547b1c5bc.tar.gz gradecoin-c3ba5ad5ebe1d5bb28ed0a340af93e8547b1c5bc.tar.bz2 gradecoin-c3ba5ad5ebe1d5bb28ed0a340af93e8547b1c5bc.zip | |
Initial commit
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 | } | ||
