From 617028cd2606a09085245550c4e4b2e2fec44503 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 31 Oct 2022 00:05:25 +0800 Subject: [PATCH] feat: add array for entites support #9 --- fkl_cli/src/mock/stub_aggregate_api.rs | 29 ++++++++++++++++++++++++++ fkl_cli/src/mock/stub_server.rs | 1 + 2 files changed, 30 insertions(+) diff --git a/fkl_cli/src/mock/stub_aggregate_api.rs b/fkl_cli/src/mock/stub_aggregate_api.rs index 241ef6f..bd26eb8 100644 --- a/fkl_cli/src/mock/stub_aggregate_api.rs +++ b/fkl_cli/src/mock/stub_aggregate_api.rs @@ -32,3 +32,32 @@ pub async fn get_aggregate_by_id( msg: format!("Could not find aggregate with name {}", aggregate_name) }.into())); } + + +#[get("//")] +pub async fn get_entities( + aggregate_name: &str, + entity_name: &str, + config: &State, +) -> Result>>, NotFound>> { + for bc in &config.context_map.contexts { + for aggregate in &bc.aggregates { + if aggregate.name.to_lowercase() == aggregate_name.to_lowercase() { + for entity in &aggregate.entities { + if entity.name.to_lowercase() == entity_name.to_lowercase() { + let mut vec = vec![]; + for _ in 0..20 { + vec.push(mock_struct(&entity.fields)); + } + return Ok(Json(vec)); + } + } + } + } + } + + return Err(NotFound(ApiError { + msg: format!("Could not find aggregate with name {}", aggregate_name) + }.into())); +} + diff --git a/fkl_cli/src/mock/stub_server.rs b/fkl_cli/src/mock/stub_server.rs index 48b2d1a..7b991e2 100644 --- a/fkl_cli/src/mock/stub_server.rs +++ b/fkl_cli/src/mock/stub_server.rs @@ -45,6 +45,7 @@ pub fn feakin_rocket(context_map: &ContextMap) -> Rocket { ]) .mount("/api", routes![ stub_aggregate_api::get_aggregate_by_id, + stub_aggregate_api::get_entities, ]) .attach(AdHoc::config::()) }