| 17 | } |
| 18 | |
| 19 | async fn build_routes(store: store::Store) -> impl Filter<Extract = impl Reply> + Clone { |
| 20 | let store_filter = warp::any().map(move || store.clone()); |
| 21 | |
| 22 | let cors = warp::cors() |
| 23 | .allow_any_origin() |
| 24 | .allow_header("content-type") |
| 25 | .allow_methods(&[Method::PUT, Method::DELETE, Method::GET, Method::POST]); |
| 26 | |
| 27 | let get_questions = warp::get() |
| 28 | .and(warp::path("questions")) |
| 29 | .and(warp::path::end()) |
| 30 | .and(warp::query()) |
| 31 | .and(store_filter.clone()) |
| 32 | .and_then(routes::question::get_questions); |
| 33 | |
| 34 | let update_question = warp::put() |
| 35 | .and(warp::path("questions")) |
| 36 | .and(warp::path::param::<i32>()) |
| 37 | .and(warp::path::end()) |
| 38 | .and(routes::authentication::auth()) |
| 39 | .and(store_filter.clone()) |
| 40 | .and(warp::body::json()) |
| 41 | .and_then(routes::question::update_question); |
| 42 | |
| 43 | let delete_question = warp::delete() |
| 44 | .and(warp::path("questions")) |
| 45 | .and(warp::path::param::<i32>()) |
| 46 | .and(warp::path::end()) |
| 47 | .and(routes::authentication::auth()) |
| 48 | .and(store_filter.clone()) |
| 49 | .and_then(routes::question::delete_question); |
| 50 | |
| 51 | let add_question = warp::post() |
| 52 | .and(warp::path("questions")) |
| 53 | .and(warp::path::end()) |
| 54 | .and(routes::authentication::auth()) |
| 55 | .and(store_filter.clone()) |
| 56 | .and(warp::body::json()) |
| 57 | .and_then(routes::question::add_question); |
| 58 | |
| 59 | let add_answer = warp::post() |
| 60 | .and(warp::path("answers")) |
| 61 | .and(warp::path::end()) |
| 62 | .and(routes::authentication::auth()) |
| 63 | .and(store_filter.clone()) |
| 64 | .and(warp::body::form()) |
| 65 | .and_then(routes::answer::add_answer); |
| 66 | |
| 67 | let registration = warp::post() |
| 68 | .and(warp::path("registration")) |
| 69 | .and(warp::path::end()) |
| 70 | .and(store_filter.clone()) |
| 71 | .and(warp::body::json()) |
| 72 | .and_then(routes::authentication::register); |
| 73 | |
| 74 | let login = warp::post() |
| 75 | .and(warp::path("login")) |
| 76 | .and(warp::path::end()) |