implement get single index

This commit is contained in:
mpostma 2021-03-06 20:17:58 +01:00
parent 281a445998
commit ced32afd9f
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
3 changed files with 15 additions and 7 deletions

View File

@ -86,12 +86,8 @@ impl Data {
self.index_controller.list_indexes().await self.index_controller.list_indexes().await
} }
pub fn index(&self, name: impl AsRef<str>) -> anyhow::Result<Option<IndexMetadata>> { pub async fn index(&self, name: impl AsRef<str>) -> anyhow::Result<Option<IndexMetadata>> {
todo!() self.index_controller.get_index(name.as_ref().to_string()).await
//Ok(self
//.list_indexes()?
//.into_iter()
//.find(|i| i.uid == name.as_ref()))
} }
pub async fn create_index(&self, name: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> { pub async fn create_index(&self, name: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> {

View File

@ -239,6 +239,18 @@ impl IndexController {
let result = self.index_handle.search(uuid, query).await?; let result = self.index_handle.search(uuid, query).await?;
Ok(result) Ok(result)
} }
pub async fn get_index(&self, name: String) -> anyhow::Result<Option<IndexMetadata>> {
let uuid = self.uuid_resolver.resolve(name.clone()).await?;
if let Some(uuid) = uuid {
let result = self.index_handle
.get_index_meta(uuid)
.await?
.map(|meta| IndexMetadata { name, meta });
return Ok(result)
}
Ok(None)
}
} }
pub async fn get_arc_ownership_blocking<T>(mut item: Arc<T>) -> T { pub async fn get_arc_ownership_blocking<T>(mut item: Arc<T>) -> T {

View File

@ -37,7 +37,7 @@ async fn get_index(
data: web::Data<Data>, data: web::Data<Data>,
path: web::Path<IndexParam>, path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
match data.index(&path.index_uid)? { match data.index(&path.index_uid).await? {
Some(meta) => { Some(meta) => {
let json = serde_json::to_string(&meta).unwrap(); let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))