autoendpoint/extractors/
registration_path_args.rs1use crate::error::{ApiError, ApiErrorKind};
2use crate::extractors::routers::RouterType;
3use actix_web::{dev::Payload, FromRequest, HttpRequest};
4use futures::future;
5
6pub struct RegistrationPathArgs {
8 pub router_type: RouterType,
9 pub app_id: String,
10}
11
12impl FromRequest for RegistrationPathArgs {
13 type Error = ApiError;
14 type Future = future::Ready<Result<Self, Self::Error>>;
15
16 fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
17 let match_info = req.match_info();
18 let router_type = match match_info
19 .get("router_type")
20 .expect("{router_type} must be part of the path")
21 .parse::<RouterType>()
22 {
23 Ok(router_type) => router_type,
24 Err(_) => return future::err(ApiErrorKind::InvalidRouterType.into()),
25 };
26 let app_id = match_info
27 .get("app_id")
28 .expect("{app_id} must be part of the path")
29 .to_string();
30
31 future::ok(Self {
32 router_type,
33 app_id,
34 })
35 }
36}