Skip to content

Commit

Permalink
use mapp_err
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Nov 21, 2023
1 parent 820a507 commit 4d6b653
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions entity_api/src/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub async fn find_all(db: &DatabaseConnection) -> Vec<Model> {
}

pub async fn find_by_id(db: &DatabaseConnection, id: i32) -> Result<Option<Model>, Error> {
match Entity::find_by_id(id).one(db).await {
Ok(result) => Ok(result),
Err(error) => Err(error.into()),
}
Entity::find_by_id(id)
.one(db)
.await
.map_err(|err| err.into())
}

pub(crate) async fn seed_database(db: &DatabaseConnection) {
Expand Down
7 changes: 3 additions & 4 deletions web/src/controller/organization_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ impl OrganizationController {
debug!("GET Organization by id: {}", id);

let organization: Result<Option<organization::Model>, Error> =
match OrganizationApi::find_by_id(&app_state.database_connection.unwrap(), id).await {
Ok(result) => Ok(result),
Err(error) => Err(error.into()),
};
OrganizationApi::find_by_id(&app_state.database_connection.unwrap(), id)
.await
.map_err(|err| err.into());

Json(organization)
}
Expand Down

0 comments on commit 4d6b653

Please sign in to comment.