-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b1cba9
commit 592a3ef
Showing
6 changed files
with
83 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,62 @@ | ||
use super::error::*; | ||
use super::state::*; | ||
use crate::rest_api::error::MetaApiError::NotFound; | ||
use axum::extract::{Path, Query, State}; | ||
use axum::extract::{Path, State}; | ||
use axum::Json; | ||
use serde::{Deserialize, Serialize}; | ||
use serde::Serialize; | ||
use service_metadata::MethodDescriptorRegistry; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct ListMethodsRequest {} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct ListMethodsResponse { | ||
methods: Vec<GetMethodResponse>, | ||
pub struct ListServiceMethodsResponse { | ||
methods: Vec<GetServiceMethodResponse>, | ||
} | ||
|
||
/// List discovered methods for service | ||
pub async fn list_methods<S, M: MethodDescriptorRegistry>( | ||
pub async fn list_service_methods<S, M: MethodDescriptorRegistry>( | ||
State(state): State<Arc<RestEndpointState<S, M>>>, | ||
Path(service_name): Path<String>, | ||
Query(_): Query<ListMethodsRequest>, | ||
) -> Result<Json<ListMethodsResponse>, MetaApiError> { | ||
) -> Result<Json<ListServiceMethodsResponse>, MetaApiError> { | ||
match state | ||
.method_descriptor_registry() | ||
.list_methods(service_name.as_str()) | ||
{ | ||
Some(methods) => Ok(ListMethodsResponse { | ||
Some(methods) => Ok(ListServiceMethodsResponse { | ||
methods: methods | ||
.keys() | ||
.map(|method_name| GetMethodResponse { | ||
.map(|method_name| GetServiceMethodResponse { | ||
service_name: service_name.clone(), | ||
method_name: method_name.clone(), | ||
}) | ||
.collect(), | ||
} | ||
.into()), | ||
None => Err(NotFound("service", service_name)), | ||
None => Err(MetaApiError::ServiceNotFound(service_name)), | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct GetMethodRequest {} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct GetMethodResponse { | ||
pub struct GetServiceMethodResponse { | ||
service_name: String, | ||
method_name: String, | ||
} | ||
|
||
/// Get an method of a service | ||
pub async fn get_method<S, M: MethodDescriptorRegistry>( | ||
pub async fn get_service_method<S, M: MethodDescriptorRegistry>( | ||
State(state): State<Arc<RestEndpointState<S, M>>>, | ||
Path((service_name, method_name)): Path<(String, String)>, | ||
Query(_): Query<GetMethodRequest>, | ||
) -> Result<Json<GetMethodResponse>, MetaApiError> { | ||
) -> Result<Json<GetServiceMethodResponse>, MetaApiError> { | ||
let endpoint = state | ||
.method_descriptor_registry() | ||
.resolve_method_descriptor(service_name.as_str(), method_name.as_str()); | ||
match endpoint { | ||
Some(_) => Ok(GetMethodResponse { | ||
Some(_) => Ok(GetServiceMethodResponse { | ||
service_name, | ||
method_name, | ||
} | ||
.into()), | ||
None => Err(NotFound( | ||
"method", | ||
format!("{}/{}", service_name, method_name), | ||
)), | ||
None => Err(MetaApiError::MethodNotFound { | ||
service_name, | ||
method_name, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters