From dd969a470478be720b6476e486c7dfd6da881f32 Mon Sep 17 00:00:00 2001 From: K0nnyaku Date: Wed, 18 Dec 2024 00:46:36 +0800 Subject: [PATCH 1/3] refactor: remove unnecessary map_err --- src/routes/account.rs | 3 +-- src/routes/category.rs | 7 ++----- src/routes/organization.rs | 13 ++++--------- src/routes/problem.rs | 9 +++------ 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/routes/account.rs b/src/routes/account.rs index 6f9510d..cd264fe 100644 --- a/src/routes/account.rs +++ b/src/routes/account.rs @@ -104,8 +104,7 @@ pub async fn login( login: Json>, ) -> Result { let session = session::authenticate(db, login.identity, login.password) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::Unauthorized(Json("Invalid credentials".into())))?; Ok(Response { success: true, diff --git a/src/routes/category.rs b/src/routes/category.rs index 2fae7df..949fd78 100644 --- a/src/routes/category.rs +++ b/src/routes/category.rs @@ -23,8 +23,7 @@ pub async fn create( } let data = category::create(db, category.into_inner().data) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::ServerError(Json("Failed to create category".into())))?; Ok(Json(Response { @@ -48,9 +47,7 @@ pub async fn delete( ))); } - category::delete(db, id) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))?; + category::delete(db, id).await?; Ok(Response { success: true, diff --git a/src/routes/organization.rs b/src/routes/organization.rs index cbe3920..a3bd646 100644 --- a/src/routes/organization.rs +++ b/src/routes/organization.rs @@ -25,8 +25,7 @@ pub async fn create( } let org = organization::create(db, org.id, org.into_inner().org) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::ServerError(Json( "Failed to create a new organization".into(), )))?; @@ -52,14 +51,10 @@ pub async fn delete( ))); } - organization::delete(db, id) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))?; - - remove_dir_all(Path::new("content/").join(id)) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))?; + organization::delete(db, id).await?; + remove_dir_all(Path::new("content/").join(id)).await?; + Ok(Response { success: true, message: "Organization deleted successfully".into(), diff --git a/src/routes/problem.rs b/src/routes/problem.rs index 7f02913..715d7e7 100644 --- a/src/routes/problem.rs +++ b/src/routes/problem.rs @@ -30,8 +30,7 @@ pub async fn create( } let problem = problem::create(db, problem.into_inner()) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::ServerError(Json( "Failed to create problem, please try again later.".into(), )))?; @@ -52,8 +51,7 @@ pub async fn get( auth: Json>>, ) -> Result { let problem = problem::get::(db, id) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::NotFound(Json( "Problem with specified id not found".into(), )))?; @@ -157,8 +155,7 @@ pub async fn update( } problem::update(db, id, problem.into_inner()) - .await - .map_err(|e| Error::ServerError(Json(e.to_string().into())))? + .await? .ok_or(Error::ServerError(Json( "Failed to update problem, please try again later.".into(), )))?; From a497ce8f502a800a2a9dee4d77fd8dcf3db1865e Mon Sep 17 00:00:00 2001 From: K0nnyaku Date: Wed, 18 Dec 2024 00:49:27 +0800 Subject: [PATCH 2/3] fix: fix lint --- src/routes/organization.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/routes/organization.rs b/src/routes/organization.rs index a3bd646..04b2e9c 100644 --- a/src/routes/organization.rs +++ b/src/routes/organization.rs @@ -52,9 +52,8 @@ pub async fn delete( } organization::delete(db, id).await?; - remove_dir_all(Path::new("content/").join(id)).await?; - + Ok(Response { success: true, message: "Organization deleted successfully".into(), From cb91f9f45444a76edf8c2e1ef74245bea21e38ab Mon Sep 17 00:00:00 2001 From: K0nnyaku Date: Wed, 18 Dec 2024 02:06:36 +0800 Subject: [PATCH 3/3] release: bumps version --- .changes/organization.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changes/organization.md diff --git a/.changes/organization.md b/.changes/organization.md new file mode 100644 index 0000000..eb5ac32 --- /dev/null +++ b/.changes/organization.md @@ -0,0 +1,4 @@ +--- +"algohub-server": patch:chore +--- +remove map_err \ No newline at end of file