You've already forked AstralRinth
forked from didirus/AstralRinth
Run fmt, fix dep route (#312)
This commit is contained in:
@@ -58,7 +58,8 @@ where
|
||||
{
|
||||
let github_user = get_github_user_from_token(access_token).await?;
|
||||
|
||||
let res = models::User::get_from_github_id(github_user.id, executor).await?;
|
||||
let res =
|
||||
models::User::get_from_github_id(github_user.id, executor).await?;
|
||||
|
||||
match res {
|
||||
Some(result) => Ok(User {
|
||||
|
||||
@@ -18,7 +18,9 @@ pub async fn read_from_payload(
|
||||
return Err(ApiError::InvalidInputError(String::from(err_msg)));
|
||||
} else {
|
||||
bytes.extend_from_slice(&item.map_err(|_| {
|
||||
ApiError::InvalidInputError("Unable to parse bytes in payload sent!".to_string())
|
||||
ApiError::InvalidInputError(
|
||||
"Unable to parse bytes in payload sent!".to_string(),
|
||||
)
|
||||
})?);
|
||||
}
|
||||
}
|
||||
@@ -35,13 +37,17 @@ pub async fn read_from_field(
|
||||
if bytes.len() >= cap {
|
||||
return Err(CreateError::InvalidInput(String::from(err_msg)));
|
||||
} else {
|
||||
bytes.extend_from_slice(&chunk.map_err(CreateError::MultipartError)?);
|
||||
bytes.extend_from_slice(
|
||||
&chunk.map_err(CreateError::MultipartError)?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub(crate) fn ok_or_not_found<T, U>(version_data: Option<T>) -> Result<HttpResponse, ApiError>
|
||||
pub(crate) fn ok_or_not_found<T, U>(
|
||||
version_data: Option<T>,
|
||||
) -> Result<HttpResponse, ApiError>
|
||||
where
|
||||
U: From<T> + Serialize,
|
||||
{
|
||||
|
||||
@@ -4,11 +4,15 @@ use regex::Regex;
|
||||
use validator::{ValidationErrors, ValidationErrorsKind};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref RE_URL_SAFE: Regex = Regex::new(r#"^[a-zA-Z0-9!@$()`.+,_"-]*$"#).unwrap();
|
||||
pub static ref RE_URL_SAFE: Regex =
|
||||
Regex::new(r#"^[a-zA-Z0-9!@$()`.+,_"-]*$"#).unwrap();
|
||||
}
|
||||
|
||||
//TODO: In order to ensure readability, only the first error is printed, this may need to be expanded on in the future!
|
||||
pub fn validation_errors_to_string(errors: ValidationErrors, adder: Option<String>) -> String {
|
||||
pub fn validation_errors_to_string(
|
||||
errors: ValidationErrors,
|
||||
adder: Option<String>,
|
||||
) -> String {
|
||||
let mut output = String::new();
|
||||
|
||||
let map = errors.into_errors();
|
||||
@@ -19,13 +23,19 @@ pub fn validation_errors_to_string(errors: ValidationErrors, adder: Option<Strin
|
||||
if let Some(error) = map.get(field) {
|
||||
return match error {
|
||||
ValidationErrorsKind::Struct(errors) => {
|
||||
validation_errors_to_string(*errors.clone(), Some(format!("of item {}", field)))
|
||||
validation_errors_to_string(
|
||||
*errors.clone(),
|
||||
Some(format!("of item {}", field)),
|
||||
)
|
||||
}
|
||||
ValidationErrorsKind::List(list) => {
|
||||
if let Some((index, errors)) = list.iter().next() {
|
||||
output.push_str(&*validation_errors_to_string(
|
||||
*errors.clone(),
|
||||
Some(format!("of list {} with index {}", index, field)),
|
||||
Some(format!(
|
||||
"of list {} with index {}",
|
||||
index, field
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user