mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 23:39:22 +00:00
27 lines
817 B
Rust
27 lines
817 B
Rust
|
use crate::data::error::ResultBoxError;
|
||
|
use crate::data::user::User;
|
||
|
use crate::helpers::database;
|
||
|
use crate::database_structure::USERS_TABLE;
|
||
|
|
||
|
/// User helper
|
||
|
///
|
||
|
/// @author Pierre Hubert
|
||
|
|
||
|
/// Get & return information about a user based on his email
|
||
|
pub fn find_user_by_email(email: &str) -> ResultBoxError<User> {
|
||
|
exec_get_user_query(
|
||
|
database::QueryInfo::new(USERS_TABLE).cond("mail", email))
|
||
|
}
|
||
|
|
||
|
/// Execute query & return result
|
||
|
fn exec_get_user_query(query : database::QueryInfo) -> ResultBoxError<User> {
|
||
|
database::query_row(query, |res|{
|
||
|
Ok(User {
|
||
|
id: res.get_int64("ID")?,
|
||
|
email: res.get_str("mail")?,
|
||
|
password: res.get_str("password")?,
|
||
|
first_name: res.get_str("prenom")?,
|
||
|
last_name: res.get_str("nom")?
|
||
|
})
|
||
|
})
|
||
|
}
|