diff --git a/entity_api/src/organization.rs b/entity_api/src/organization.rs index 1de9b98..51d382d 100644 --- a/entity_api/src/organization.rs +++ b/entity_api/src/organization.rs @@ -60,12 +60,15 @@ pub async fn delete_by_id(db: &DatabaseConnection, id: i32) -> Result<(), Error> } } -pub async fn find_all(db: &DatabaseConnection) -> Vec { - Entity::find().all(db).await.unwrap_or(vec![]) +pub async fn find_all(db: &DatabaseConnection) -> Result, Error> { + Ok(Entity::find().all(db).await?) } pub async fn find_by_id(db: &DatabaseConnection, id: i32) -> Result, Error> { - Ok(Entity::find_by_id(id).one(db).await?) + let organization = Entity::find_by_id(id).one(db).await?; + debug!("Organization found: {:?}", organization); + + Ok(organization) } pub(crate) async fn seed_database(db: &DatabaseConnection) { diff --git a/web/src/controller/organization_controller.rs b/web/src/controller/organization_controller.rs index 0946a93..1f8ac8d 100644 --- a/web/src/controller/organization_controller.rs +++ b/web/src/controller/organization_controller.rs @@ -16,10 +16,10 @@ impl OrganizationController { /// Test this with curl: curl --header "Content-Type: application/json" \ in zsh at 12:03:06 /// --request GET \ /// http://localhost:4000/organizations - pub async fn index(State(app_state): State) -> impl IntoResponse { - let organizations = OrganizationApi::find_all(app_state.db_conn_ref().unwrap()).await; + pub async fn index(State(app_state): State) -> Result { + let organizations = OrganizationApi::find_all(app_state.db_conn_ref().unwrap()).await?; - Json(organizations) + Ok(Json(organizations)) } /// GET a particular Organization entity specified by its primary key