fix clippy errors
This commit is contained in:
parent
463a07cc2a
commit
c4bc4a2f4b
@ -50,7 +50,7 @@ pub fn insert_new_user(
|
|||||||
// to prevent import collisions and namespace pollution.
|
// to prevent import collisions and namespace pollution.
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
let nu = {
|
let nu = {
|
||||||
let mut nu2 = nu.clone();
|
let mut nu2 = nu;
|
||||||
nu2.password = hash(&nu2.password, DEFAULT_COST)?;
|
nu2.password = hash(&nu2.password, DEFAULT_COST)?;
|
||||||
nu2
|
nu2
|
||||||
};
|
};
|
||||||
@ -61,9 +61,9 @@ pub fn insert_new_user(
|
|||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_password<'a>(
|
pub fn verify_password(
|
||||||
user_name: &'a String,
|
user_name: &str,
|
||||||
given_password: &'a String,
|
given_password: &str,
|
||||||
conn: &SqliteConnection,
|
conn: &SqliteConnection,
|
||||||
) -> Result<bool, errors::DomainError> {
|
) -> Result<bool, errors::DomainError> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
@ -84,7 +84,7 @@ mod query {
|
|||||||
type Query<'a, B, T> = crate::schema::users::BoxedQuery<'a, B, T>;
|
type Query<'a, B, T> = crate::schema::users::BoxedQuery<'a, B, T>;
|
||||||
|
|
||||||
pub fn _get_user_by_name(
|
pub fn _get_user_by_name(
|
||||||
user_name: &String,
|
user_name: &str,
|
||||||
) -> Query<Sqlite, (Text, Timestamp)> {
|
) -> Query<Sqlite, (Text, Timestamp)> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
users
|
users
|
||||||
|
@ -4,7 +4,6 @@ use custom_error::custom_error;
|
|||||||
// use derive_more::Display;
|
// use derive_more::Display;
|
||||||
// use diesel::result::DatabaseErrorKind;
|
// use diesel::result::DatabaseErrorKind;
|
||||||
use crate::models::errors::*;
|
use crate::models::errors::*;
|
||||||
use r2d2;
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
// impl From<DBError> for DomainError {
|
// impl From<DBError> for DomainError {
|
||||||
@ -56,7 +55,7 @@ impl ResponseError for DomainError {
|
|||||||
DomainError::PasswordError { cause: _ } => {
|
DomainError::PasswordError { cause: _ } => {
|
||||||
HttpResponse::BadRequest().json(ErrorModel {
|
HttpResponse::BadRequest().json(ErrorModel {
|
||||||
error_code: 400,
|
error_code: 400,
|
||||||
reason: format!("{}", err.to_string()).as_str(),
|
reason: err.to_string().as_str(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
DomainError::GenericError { cause } => HttpResponse::BadRequest()
|
DomainError::GenericError { cause } => HttpResponse::BadRequest()
|
||||||
|
@ -110,5 +110,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
server.bind(addr)?
|
server.bind(addr)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
println!("woot2");
|
||||||
|
|
||||||
server.run().await
|
server.run().await
|
||||||
}
|
}
|
||||||
|
@ -64,21 +64,21 @@ pub async fn get_all_users(
|
|||||||
actions::get_all(&conn)
|
actions::get_all(&conn)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.and_then(|maybe_users| {
|
.map(|maybe_users| {
|
||||||
debug!("{:?}", maybe_users);
|
debug!("{:?}", maybe_users);
|
||||||
if let Some(users) = maybe_users {
|
if let Some(users) = maybe_users {
|
||||||
if users.is_empty() {
|
if users.is_empty() {
|
||||||
let res = HttpResponse::NotFound()
|
let res = HttpResponse::NotFound()
|
||||||
.json(models::ErrorModel::new(40, "No users available"));
|
.json(models::ErrorModel::new(40, "No users available"));
|
||||||
// let res = crate::errors::DomainError::new_generic_error("".to_owned());
|
// let res = crate::errors::DomainError::new_generic_error("".to_owned());
|
||||||
Ok(res)
|
res
|
||||||
} else {
|
} else {
|
||||||
Ok(HttpResponse::Ok().json(users))
|
HttpResponse::Ok().json(users)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let res = HttpResponse::NotFound()
|
let res = HttpResponse::NotFound()
|
||||||
.json(models::ErrorModel::new(40, "No users available"));
|
.json(models::ErrorModel::new(40, "No users available"));
|
||||||
Ok(res)
|
res
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
res
|
res
|
||||||
@ -98,9 +98,9 @@ pub async fn add_user(
|
|||||||
actions::insert_new_user(form.0, &conn)
|
actions::insert_new_user(form.0, &conn)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.and_then(|user| {
|
.map(|user| {
|
||||||
debug!("{:?}", user);
|
debug!("{:?}", user);
|
||||||
Ok(HttpResponse::Created().json(user))
|
HttpResponse::Created().json(user)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -21,10 +21,10 @@ pub trait UserService {
|
|||||||
|
|
||||||
// fn woot(&self) -> i32;
|
// fn woot(&self) -> i32;
|
||||||
|
|
||||||
fn verify_password<'a>(
|
fn verify_password(
|
||||||
&self,
|
&self,
|
||||||
user_name: &'a String,
|
user_name: &str,
|
||||||
given_password: &'a String,
|
given_password: &str,
|
||||||
) -> Result<bool, errors::DomainError>;
|
) -> Result<bool, errors::DomainError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +65,10 @@ impl UserService for UserServiceImpl {
|
|||||||
actions::insert_new_user(nu, &conn)
|
actions::insert_new_user(nu, &conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_password<'b>(
|
fn verify_password(
|
||||||
&self,
|
&self,
|
||||||
user_name: &'b String,
|
user_name: &str,
|
||||||
given_password: &'b String,
|
given_password: &str,
|
||||||
) -> Result<bool, errors::DomainError> {
|
) -> Result<bool, errors::DomainError> {
|
||||||
let conn = self.pool.get()?;
|
let conn = self.pool.get()?;
|
||||||
actions::verify_password(user_name, given_password, &conn)
|
actions::verify_password(user_name, given_password, &conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user