This commit is contained in:
Chen Xu 2022-07-16 03:16:24 +08:00
Родитель d2fcfef6a3
Коммит b3657f0a22
3 изменённых файлов: 70 добавлений и 1 удалений

Просмотреть файл

@ -349,4 +349,27 @@ impl FeathrApiV1 {
.into_lineage()
.map(Json)
}
#[oai(
path = "/features/:feature/project",
method = "get",
tag = "ApiTags::Feature"
)]
async fn get_feature_project(
&self,
data: Data<&RaftRegistryApp>,
#[oai(name = "x-registry-opt-seq")] opt_seq: Header<Option<u64>>,
feature: Path<String>,
) -> poem::Result<Json<Entity>> {
data.0
.request(
opt_seq.0,
FeathrApiRequest::GetEntityProject {
id_or_name: feature.0,
},
)
.await
.into_entity()
.map(Json)
}
}

Просмотреть файл

@ -747,6 +747,29 @@ impl FeathrApiV2 {
.into_lineage()
.map(Json)
}
#[oai(
path = "/features/:feature/project",
method = "get",
tag = "ApiTags::Feature"
)]
async fn get_feature_project(
&self,
data: Data<&RaftRegistryApp>,
#[oai(name = "x-registry-opt-seq")] opt_seq: Header<Option<u64>>,
feature: Path<String>,
) -> poem::Result<Json<Entity>> {
data.0
.request(
opt_seq.0,
FeathrApiRequest::GetEntityProject {
id_or_name: feature.0,
},
)
.await
.into_entity()
.map(Json)
}
}
fn parse_version<T>(v: T) -> Result<Option<u64>, ApiError>

Просмотреть файл

@ -3,7 +3,9 @@ use std::collections::HashSet;
use async_trait::async_trait;
use common_utils::{set, Blank};
use log::debug;
use registry_provider::{Edge, EdgeType, EntityProperty, RegistryError, RegistryProvider};
use registry_provider::{
Edge, EdgeType, EntityProperty, EntityType, RegistryError, RegistryProvider,
};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
@ -137,6 +139,9 @@ pub enum FeathrApiRequest {
GetFeatureLineage {
id_or_name: String,
},
GetEntityProject {
id_or_name: String,
},
BatchLoad {
entities: Vec<registry_provider::Entity<EntityProperty>>,
edges: Vec<Edge>,
@ -836,6 +841,24 @@ where
FeathrApiRequest::BatchLoad { entities, edges } => {
this.load_data(entities, edges).await.into()
}
FeathrApiRequest::GetEntityProject { id_or_name } => {
let entity = this.get_entity_by_id_or_qualified_name(&id_or_name)?;
if entity.entity_type == EntityType::Project {
fill_entity(this, entity).into()
} else {
let id = get_id(this, id_or_name.clone())?;
let containers = this.get_neighbors(id, EdgeType::BelongsTo)?;
containers
.iter()
.find(|c| c.entity_type == EntityType::Project)
.map(|c| fill_entity(this, c.to_owned()))
.ok_or(RegistryError::EntityNotFound(format!(
"Entity {} doesn't belong to any project",
id_or_name
)))?
.into()
}
}
})
}