mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	Add a route to server user details
This commit is contained in:
		
							parent
							
								
									b0c721bb28
								
							
						
					
					
						commit
						5a3332430f
					
				@ -5,7 +5,7 @@ use crate::{
 | 
				
			|||||||
        tcp_server::{error_to_http_response, AppState},
 | 
					        tcp_server::{error_to_http_response, AppState},
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use actix_web::{web, HttpResponse};
 | 
					use actix_web::{web, HttpRequest, HttpResponse};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub(crate) fn error_to_api_response<T>(error: DomainError) -> ApiResult<T> {
 | 
					pub(crate) fn error_to_api_response<T>(error: DomainError) -> ApiResult<T> {
 | 
				
			||||||
    ApiResult::Right(error_to_http_response(error))
 | 
					    ApiResult::Right(error_to_http_response(error))
 | 
				
			||||||
@ -28,6 +28,23 @@ where
 | 
				
			|||||||
        .unwrap_or_else(error_to_api_response)
 | 
					        .unwrap_or_else(error_to_api_response)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async fn user_details_handler<Backend>(
 | 
				
			||||||
 | 
					    data: web::Data<AppState<Backend>>,
 | 
				
			||||||
 | 
					    request: HttpRequest,
 | 
				
			||||||
 | 
					) -> ApiResult<User>
 | 
				
			||||||
 | 
					where
 | 
				
			||||||
 | 
					    Backend: TcpBackendHandler + BackendHandler + 'static,
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    let request = UserDetailsRequest {
 | 
				
			||||||
 | 
					        user_id: request.match_info().get("user_id").unwrap().to_string(),
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    data.backend_handler
 | 
				
			||||||
 | 
					        .get_user_details(request)
 | 
				
			||||||
 | 
					        .await
 | 
				
			||||||
 | 
					        .map(|res| ApiResult::Left(web::Json(res)))
 | 
				
			||||||
 | 
					        .unwrap_or_else(error_to_api_response)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async fn create_user_handler<Backend>(
 | 
					async fn create_user_handler<Backend>(
 | 
				
			||||||
    data: web::Data<AppState<Backend>>,
 | 
					    data: web::Data<AppState<Backend>>,
 | 
				
			||||||
    info: web::Json<CreateUserRequest>,
 | 
					    info: web::Json<CreateUserRequest>,
 | 
				
			||||||
@ -59,9 +76,16 @@ where
 | 
				
			|||||||
            .into()
 | 
					            .into()
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    cfg.app_data(json_config);
 | 
					    cfg.app_data(json_config);
 | 
				
			||||||
    cfg.service(web::resource("/users").route(web::post().to(user_list_handler::<Backend>)));
 | 
					 | 
				
			||||||
    cfg.service(
 | 
					    cfg.service(
 | 
				
			||||||
        web::resource("/users/create").route(web::post().to(create_user_handler::<Backend>)),
 | 
					        web::resource("/user/{user_id}").route(web::get().to(user_details_handler::<Backend>)),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    cfg.service(
 | 
				
			||||||
 | 
					        web::scope("/users")
 | 
				
			||||||
 | 
					            .guard(actix_web::guard::Header("content-type", "application/json"))
 | 
				
			||||||
 | 
					            .service(web::resource("").route(web::post().to(user_list_handler::<Backend>)))
 | 
				
			||||||
 | 
					            .service(
 | 
				
			||||||
 | 
					                web::resource("/create").route(web::post().to(create_user_handler::<Backend>)),
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -68,7 +68,6 @@ fn http_config<Backend>(
 | 
				
			|||||||
                auth_service::token_validator::<Backend>,
 | 
					                auth_service::token_validator::<Backend>,
 | 
				
			||||||
            ))
 | 
					            ))
 | 
				
			||||||
            .wrap(auth_service::CookieToHeaderTranslatorFactory)
 | 
					            .wrap(auth_service::CookieToHeaderTranslatorFactory)
 | 
				
			||||||
            .guard(actix_web::guard::Header("content-type", "application/json"))
 | 
					 | 
				
			||||||
            .configure(tcp_api::api_config::<Backend>),
 | 
					            .configure(tcp_api::api_config::<Backend>),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    // Serve the /pkg path with the compiled WASM app.
 | 
					    // Serve the /pkg path with the compiled WASM app.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user