1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-29 16:56:28 +00:00
comunicapiv3/src/helpers/api_helper.rs

27 lines
828 B
Rust

use crate::data::api_client::APIClient;
use crate::helpers::database;
use crate::helpers::database::QueryInfo;
use crate::constants::database_tables_names::SERVICES_TABLES;
use crate::data::error::ResultBoxError;
/// API helper
///
/// @author Pierre Hubert
/// Get information about a client
pub fn get_client(name: &str, token: &str) -> ResultBoxError<APIClient> {
database::query_row(
QueryInfo::new(SERVICES_TABLES)
.cond("service_name", name)
.cond("token", token),
|res| {
Ok(APIClient {
id: res.get_int64("id")? as u32,
name: res.get_str("service_name")?,
token: res.get_str("token")?,
domain: res.get_optional_str("client_domain")?,
})
}
)
}