Skip to content

Commit

Permalink
feat: add array for entites support #9
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 30, 2022
1 parent 5f4d7a1 commit 617028c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions fkl_cli/src/mock/stub_aggregate_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,32 @@ pub async fn get_aggregate_by_id(
msg: format!("Could not find aggregate with name {}", aggregate_name)
}.into()));
}


#[get("/<aggregate_name>/<entity_name>")]
pub async fn get_entities(
aggregate_name: &str,
entity_name: &str,
config: &State<MockServerConfig>,
) -> Result<Json<Vec<IndexMap<String, FakeValue>>>, NotFound<Json<ApiError>>> {
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()));
}

1 change: 1 addition & 0 deletions fkl_cli/src/mock/stub_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn feakin_rocket(context_map: &ContextMap) -> Rocket<Build> {
])
.mount("/api", routes![
stub_aggregate_api::get_aggregate_by_id,
stub_aggregate_api::get_entities,
])
.attach(AdHoc::config::<MockServerConfig>())
}
Expand Down

0 comments on commit 617028c

Please sign in to comment.