Skip to content

Commit

Permalink
chore: remove unnecessary map_err (#67)
Browse files Browse the repository at this point in the history
* refactor: remove unnecessary map_err

* fix: fix lint

* release: bumps version
  • Loading branch information
K0nnyaku authored Dec 17, 2024
1 parent 5ac5d25 commit 886474e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .changes/organization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"algohub-server": patch:chore
---
remove map_err
3 changes: 1 addition & 2 deletions src/routes/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ pub async fn login(
login: Json<Login<'_>>,
) -> Result<OwnedCredentials> {
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,
Expand Down
7 changes: 2 additions & 5 deletions src/routes/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
12 changes: 3 additions & 9 deletions src/routes/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)))?;
Expand All @@ -52,13 +51,8 @@ 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,
Expand Down
9 changes: 3 additions & 6 deletions src/routes/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)))?;
Expand All @@ -52,8 +51,7 @@ pub async fn get(
auth: Json<Option<Credentials<'_>>>,
) -> Result<UserProblem> {
let problem = problem::get::<Problem>(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(),
)))?;
Expand Down Expand Up @@ -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(),
)))?;
Expand Down

0 comments on commit 886474e

Please sign in to comment.