Skip to content

Commit

Permalink
format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
huangcheng committed Dec 1, 2023
1 parent 8aa8e13 commit cfdf902
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
6 changes: 0 additions & 6 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ impl From<std::num::ParseIntError> for ServiceError {
}
}

impl Into<Status> for ServiceError {
fn into(self) -> Status {
self.status()
}
}

impl ServiceError {
pub fn status(&self) -> Status {
match self {
Expand Down
1 change: 0 additions & 1 deletion src/handlers/site.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rocket::form::validate::Len;
use rocket_db_pools::Connection;
use sqlx::{query, query_as, Row};

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/upload.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fs;
use std::io;
use std::path::PathBuf;
use std::path::Path;

use log::error;
use rocket::fs::TempFile;
use sha2::{Digest, Sha256};

use crate::errors::ServiceError;

pub async fn upload(file: &TempFile<'_>, path: &PathBuf) -> Result<String, ServiceError> {
pub async fn upload(file: &TempFile<'_>, path: &Path) -> Result<String, ServiceError> {
let content_type = match file.content_type() {
Some(content_type) => content_type,
None => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn login(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(response::auth::JwtToken { token })
Expand Down
18 changes: 7 additions & 11 deletions src/routes/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn all(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Json(result))
Expand All @@ -59,7 +59,7 @@ pub async fn update<'r>(
update_category(id, &category, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand All @@ -77,7 +77,7 @@ pub async fn add<'r>(
let icon = standardize_url(category.icon, &config.upload_url);

let icon = match icon {
Some(icon) => String::from(icon),
Some(icon) => icon,
None => String::from(category.icon),
};

Expand All @@ -86,22 +86,18 @@ pub async fn add<'r>(
add_category(&category, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
}

#[delete("/<id>")]
pub async fn delete<'r>(
id: &'r str,
mut db: Connection<Db>,
_jwt: JwtMiddleware,
) -> Result<(), Status> {
pub async fn delete(id: &str, mut db: Connection<Db>, _jwt: JwtMiddleware) -> Result<(), Status> {
delete_category(id, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand All @@ -118,7 +114,7 @@ pub async fn get_sites(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Json(sites))
Expand Down
10 changes: 5 additions & 5 deletions src/routes/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn all(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Json(result))
Expand All @@ -49,7 +49,7 @@ pub async fn add(
let icon = standardize_url(site.icon, &config.upload_url);

let icon = match icon {
Some(icon) => String::from(icon),
Some(icon) => icon,
None => String::from(site.icon),
};

Expand All @@ -58,7 +58,7 @@ pub async fn add(
site::add_site(&site, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand All @@ -84,7 +84,7 @@ pub async fn update<'r>(
site::update_site(id, &site, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand All @@ -95,7 +95,7 @@ pub async fn delete(id: &str, mut db: Connection<Db>, _jwt: JwtMiddleware) -> Re
site::delete_site(id, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/routes/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn upload(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Json(format!("{}/{}", config.upload_url, result)))
Expand Down
6 changes: 3 additions & 3 deletions src/routes/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn me(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Json(user))
Expand All @@ -54,7 +54,7 @@ pub async fn update(
update_user(username, &user, &mut db).await.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(())
Expand All @@ -72,7 +72,7 @@ pub async fn update_password<'r>(
.map_err(|e| {
error!("{}", e);

e.into()
e.status()
})?;

Ok(Logout)
Expand Down

0 comments on commit cfdf902

Please sign in to comment.