Convert format macros to new format
This commit is contained in:
parent
19ba3a750b
commit
1eb31f8e1e
@ -22,7 +22,7 @@ impl APVariables {
|
|||||||
user_id: &str,
|
user_id: &str,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let url = format!("{}/users/{}/sessions", self.endpoint, user_id);
|
let url = format!("{}/users/{user_id}/sessions", self.endpoint);
|
||||||
let response = client
|
let response = client
|
||||||
.get(url)
|
.get(url)
|
||||||
.header("X-Appwrite-Key", self.api_key.clone())
|
.header("X-Appwrite-Key", self.api_key.clone())
|
||||||
|
@ -47,10 +47,7 @@ impl std::fmt::Display for DatabaseError {
|
|||||||
impl IntoFieldError for DatabaseError {
|
impl IntoFieldError for DatabaseError {
|
||||||
fn into_field_error(self) -> juniper::FieldError<DefaultScalarValue> {
|
fn into_field_error(self) -> juniper::FieldError<DefaultScalarValue> {
|
||||||
let short = self.short;
|
let short = self.short;
|
||||||
FieldError::new(
|
FieldError::new(self.long, graphql_value!({ "error": short }))
|
||||||
self.long,
|
|
||||||
graphql_value!({ "error": short }),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +85,7 @@ impl Database {
|
|||||||
{
|
{
|
||||||
self.conn.get().map_err(|e| {
|
self.conn.get().map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to connect to database: {:?}", e),
|
format!("Failed to connect to database: {e:?}"),
|
||||||
"Database connection error",
|
"Database connection error",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -99,11 +96,11 @@ impl Database {
|
|||||||
languages
|
languages
|
||||||
.load::<Language>(&mut self.conn()?)
|
.load::<Language>(&mut self.conn()?)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
info!("Failed to retrieve languages from database: {:?}", e);
|
info!("Failed to retrieve languages from database: {e:?}");
|
||||||
})
|
})
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to retrieve languages: {:?}", e),
|
format!("Failed to retrieve languages: {e:?}"),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -113,7 +110,7 @@ impl Database {
|
|||||||
use self::schema::users::dsl::users;
|
use self::schema::users::dsl::users;
|
||||||
users.load::<User>(&mut self.conn()?).map_err(|e| {
|
users.load::<User>(&mut self.conn()?).map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to retrieve languages: {:?}", e),
|
format!("Failed to retrieve languages: {e:?}"),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -125,13 +122,12 @@ impl Database {
|
|||||||
) -> Result<Vec<Language>, DatabaseError> {
|
) -> Result<Vec<Language>, DatabaseError> {
|
||||||
use self::schema::languages::dsl;
|
use self::schema::languages::dsl;
|
||||||
dsl::languages
|
dsl::languages
|
||||||
.filter(dsl::name.ilike(format!("%{}%", query)))
|
.filter(dsl::name.ilike(format!("%{query}%")))
|
||||||
.load::<Language>(&mut self.conn()?)
|
.load::<Language>(&mut self.conn()?)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve languages with query {}: {:?}",
|
"Failed to retrieve languages with query {query}: {e:?}"
|
||||||
query, e
|
|
||||||
),
|
),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
@ -141,13 +137,12 @@ impl Database {
|
|||||||
pub fn find_user(&self, query: &str) -> Result<Vec<User>, DatabaseError> {
|
pub fn find_user(&self, query: &str) -> Result<Vec<User>, DatabaseError> {
|
||||||
use self::schema::users::dsl;
|
use self::schema::users::dsl;
|
||||||
dsl::users
|
dsl::users
|
||||||
.filter(dsl::username.ilike(format!("%{}%", query)))
|
.filter(dsl::username.ilike(format!("%{query}%")))
|
||||||
.load::<User>(&mut self.conn()?)
|
.load::<User>(&mut self.conn()?)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve users with query {}: {:?}",
|
"Failed to retrieve users with query {query}: {e:?}"
|
||||||
query, e
|
|
||||||
),
|
),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
@ -169,8 +164,7 @@ impl Database {
|
|||||||
Err(Error::NotFound) => Ok(None),
|
Err(Error::NotFound) => Ok(None),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to find language {} belonging to {}: {:?}",
|
"Failed to find language {name} belonging to {owner}: {e:?}"
|
||||||
name, owner, e
|
|
||||||
),
|
),
|
||||||
"Database error",
|
"Database error",
|
||||||
)),
|
)),
|
||||||
@ -183,10 +177,7 @@ impl Database {
|
|||||||
Ok(val) => Ok(Some(val)),
|
Ok(val) => Ok(Some(val)),
|
||||||
Err(Error::NotFound) => Ok(None),
|
Err(Error::NotFound) => Ok(None),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!(
|
format!("Failed to retrieve user {id} from database: {e:?}"),
|
||||||
"Failed to retrieve user {} from database: {:?}",
|
|
||||||
id, e
|
|
||||||
),
|
|
||||||
"Database Error",
|
"Database Error",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
@ -202,14 +193,14 @@ impl Database {
|
|||||||
match insert_into(users).values(user.clone()).execute(
|
match insert_into(users).values(user.clone()).execute(
|
||||||
&mut self.conn().map_err(|e| {
|
&mut self.conn().map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to connect to the database: {:?}", e),
|
format!("Failed to connect to the database: {e:?}"),
|
||||||
"Connection error",
|
"Connection error",
|
||||||
)
|
)
|
||||||
})?,
|
})?,
|
||||||
) {
|
) {
|
||||||
Ok(_) => Ok(user),
|
Ok(_) => Ok(user),
|
||||||
Err(e) => Err(DatabaseError {
|
Err(e) => Err(DatabaseError {
|
||||||
long: format!("Failed to insert user {:?}: {:?}", user, e),
|
long: format!("Failed to insert user {user:?}: {e:?}"),
|
||||||
short: "Data insertion error".to_string(),
|
short: "Data insertion error".to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -222,7 +213,7 @@ impl Database {
|
|||||||
{
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to delete user {}: {:?}", id, e),
|
format!("Failed to delete user {id}: {e:?}"),
|
||||||
"User deletion error",
|
"User deletion error",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
@ -234,10 +225,7 @@ impl Database {
|
|||||||
Ok(val) => Ok(Some(val)),
|
Ok(val) => Ok(Some(val)),
|
||||||
Err(Error::NotFound) => Ok(None),
|
Err(Error::NotFound) => Ok(None),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!(
|
format!("Failed to retrieve word {id} from database: {e:?}"),
|
||||||
"Failed to retrieve word {} from database: {:?}",
|
|
||||||
id, e
|
|
||||||
),
|
|
||||||
"Database Error",
|
"Database Error",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
@ -256,8 +244,7 @@ impl Database {
|
|||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve word {} from language {}: {:?}",
|
"Failed to retrieve word {word} from language {language}: {e:?}"
|
||||||
word, language, e
|
|
||||||
),
|
),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
@ -272,14 +259,12 @@ impl Database {
|
|||||||
use self::schema::words::dsl;
|
use self::schema::words::dsl;
|
||||||
dsl::words
|
dsl::words
|
||||||
.filter(dsl::language.eq(language))
|
.filter(dsl::language.eq(language))
|
||||||
.filter(dsl::norm.ilike(format!("%{}%", query)))
|
.filter(dsl::norm.ilike(format!("%{query}%")))
|
||||||
.load::<Word>(&mut self.conn()?)
|
.load::<Word>(&mut self.conn()?)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve words from language {} with query {}: {:?}",
|
"Failed to retrieve words from language {language} with query {query}: {e:?}"
|
||||||
language,
|
|
||||||
query, e
|
|
||||||
),
|
),
|
||||||
"Failed to retrieve languages",
|
"Failed to retrieve languages",
|
||||||
)
|
)
|
||||||
|
@ -147,8 +147,7 @@ impl Language {
|
|||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve language translations: {:?}",
|
"Failed to retrieve language translations: {e:?}"
|
||||||
e
|
|
||||||
),
|
),
|
||||||
"Database reading failure",
|
"Database reading failure",
|
||||||
)
|
)
|
||||||
@ -160,7 +159,7 @@ impl Language {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<Language>>()),
|
.collect::<Vec<Language>>()),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to connect to the database: {:?}", e),
|
format!("Failed to connect to the database: {e:?}"),
|
||||||
"Database connection failure",
|
"Database connection failure",
|
||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
@ -218,14 +217,14 @@ impl Language {
|
|||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve owner {} of language {}: {:?}",
|
"Failed to retrieve owner {} of language {}: {e:?}",
|
||||||
self.owner, self.name, e
|
self.owner, self.name
|
||||||
),
|
),
|
||||||
"Database reading error",
|
"Database reading error",
|
||||||
)
|
)
|
||||||
})?),
|
})?),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to connect to the database: {:?}", e),
|
format!("Failed to connect to the database: {e:?}"),
|
||||||
"Database connection failure",
|
"Database connection failure",
|
||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
|
@ -28,7 +28,7 @@ impl User {
|
|||||||
use super::super::schema::{userfollows, users};
|
use super::super::schema::{userfollows, users};
|
||||||
let conn = &mut context.db.conn().map_err(|e| {
|
let conn = &mut context.db.conn().map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to connect to database: {:?}", e),
|
format!("Failed to connect to database: {e:?}"),
|
||||||
"Database connection error",
|
"Database connection error",
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@ -38,8 +38,7 @@ impl User {
|
|||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!(
|
format!(
|
||||||
"Failed to retrieve user follows from database: {:?}",
|
"Failed to retrieve user follows from database: {e:?}"
|
||||||
e
|
|
||||||
),
|
),
|
||||||
"Database reading error",
|
"Database reading error",
|
||||||
)
|
)
|
||||||
@ -52,9 +51,8 @@ impl User {
|
|||||||
Ok(val) => Some(val),
|
Ok(val) => Some(val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let err = DatabaseError::new(
|
let err = DatabaseError::new(
|
||||||
format!("Failed to retrieve user {} from database: {:?}",
|
format!("Failed to retrieve user {} from database: {e:?}",
|
||||||
f.following.clone(),
|
f.following.clone()),
|
||||||
e),
|
|
||||||
"Database reading error");
|
"Database reading error");
|
||||||
debug!("{}", err);
|
debug!("{}", err);
|
||||||
None
|
None
|
||||||
|
@ -76,7 +76,7 @@ impl Word {
|
|||||||
.load::<WordRelation>(conn)
|
.load::<WordRelation>(conn)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
DatabaseError::new(
|
DatabaseError::new(
|
||||||
format!("Failed to retrieve word relations: {:?}", e),
|
format!("Failed to retrieve word relations: {e:?}"),
|
||||||
"Database reading failed",
|
"Database reading failed",
|
||||||
)
|
)
|
||||||
})?
|
})?
|
||||||
@ -87,7 +87,7 @@ impl Word {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<Word>>()),
|
.collect::<Vec<Word>>()),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to connect to the database: {:?}", e),
|
format!("Failed to connect to the database: {e:?}"),
|
||||||
"Database connection error",
|
"Database connection error",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ impl Query {
|
|||||||
.find_word(uuid, query.as_str())
|
.find_word(uuid, query.as_str())
|
||||||
.map_err(Into::into),
|
.map_err(Into::into),
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to convert {} to a UUID: {:?}", language, e),
|
format!("Failed to convert {language} to a UUID: {e:?}"),
|
||||||
"Conversion Error",
|
"Conversion Error",
|
||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
@ -147,7 +147,7 @@ impl Query {
|
|||||||
context.db.words(uuid, word.as_str()).map_err(Into::into)
|
context.db.words(uuid, word.as_str()).map_err(Into::into)
|
||||||
}
|
}
|
||||||
Err(e) => Err(DatabaseError::new(
|
Err(e) => Err(DatabaseError::new(
|
||||||
format!("Failed to convert {} to a UUID: {:?}", language, e),
|
format!("Failed to convert {language} to a UUID: {e:?}"),
|
||||||
"Conversion Error",
|
"Conversion Error",
|
||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
|
Loading…
Reference in New Issue
Block a user