Browse Source

fix clippy errors

devel
Rohan Sircar 3 years ago
parent
commit
c4bc4a2f4b
  1. 10
      src/actions/users.rs
  2. 3
      src/errors/domain_error.rs
  3. 2
      src/main.rs
  4. 12
      src/routes/users.rs
  5. 12
      src/services/user_service.rs

10
src/actions/users.rs

@ -50,7 +50,7 @@ pub fn insert_new_user(
// to prevent import collisions and namespace pollution.
use crate::schema::users::dsl::*;
let nu = {
let mut nu2 = nu.clone();
let mut nu2 = nu;
nu2.password = hash(&nu2.password, DEFAULT_COST)?;
nu2
};
@ -61,9 +61,9 @@ pub fn insert_new_user(
Ok(user)
}
pub fn verify_password<'a>(
user_name: &'a String,
given_password: &'a String,
pub fn verify_password(
user_name: &str,
given_password: &str,
conn: &SqliteConnection,
) -> Result<bool, errors::DomainError> {
use crate::schema::users::dsl::*;
@ -84,7 +84,7 @@ mod query {
type Query<'a, B, T> = crate::schema::users::BoxedQuery<'a, B, T>;
pub fn _get_user_by_name(
user_name: &String,
user_name: &str,
) -> Query<Sqlite, (Text, Timestamp)> {
use crate::schema::users::dsl::*;
users

3
src/errors/domain_error.rs

@ -4,7 +4,6 @@ use custom_error::custom_error;
// use derive_more::Display;
// use diesel::result::DatabaseErrorKind;
use crate::models::errors::*;
use r2d2;
use std::convert::From;
// impl From<DBError> for DomainError {
@ -56,7 +55,7 @@ impl ResponseError for DomainError {
DomainError::PasswordError { cause: _ } => {
HttpResponse::BadRequest().json(ErrorModel {
error_code: 400,
reason: format!("{}", err.to_string()).as_str(),
reason: err.to_string().as_str(),
})
}
DomainError::GenericError { cause } => HttpResponse::BadRequest()

2
src/main.rs

@ -110,5 +110,7 @@ async fn main() -> std::io::Result<()> {
server.bind(addr)?
};
println!("woot2");
server.run().await
}

12
src/routes/users.rs

@ -64,21 +64,21 @@ pub async fn get_all_users(
actions::get_all(&conn)
})
.await
.and_then(|maybe_users| {
.map(|maybe_users| {
debug!("{:?}", maybe_users);
if let Some(users) = maybe_users {
if users.is_empty() {
let res = HttpResponse::NotFound()
.json(models::ErrorModel::new(40, "No users available"));
// let res = crate::errors::DomainError::new_generic_error("".to_owned());
Ok(res)
res
} else {
Ok(HttpResponse::Ok().json(users))
HttpResponse::Ok().json(users)
}
} else {
let res = HttpResponse::NotFound()
.json(models::ErrorModel::new(40, "No users available"));
Ok(res)
res
}
});
res
@ -98,9 +98,9 @@ pub async fn add_user(
actions::insert_new_user(form.0, &conn)
})
.await
.and_then(|user| {
.map(|user| {
debug!("{:?}", user);
Ok(HttpResponse::Created().json(user))
HttpResponse::Created().json(user)
}),
Err(e) => {

12
src/services/user_service.rs

@ -21,10 +21,10 @@ pub trait UserService {
// fn woot(&self) -> i32;
fn verify_password<'a>(
fn verify_password(
&self,
user_name: &'a String,
given_password: &'a String,
user_name: &str,
given_password: &str,
) -> Result<bool, errors::DomainError>;
}
@ -65,10 +65,10 @@ impl UserService for UserServiceImpl {
actions::insert_new_user(nu, &conn)
}
fn verify_password<'b>(
fn verify_password(
&self,
user_name: &'b String,
given_password: &'b String,
user_name: &str,
given_password: &str,
) -> Result<bool, errors::DomainError> {
let conn = self.pool.get()?;
actions::verify_password(user_name, given_password, &conn)

Loading…
Cancel
Save