1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-02 02:06:27 +00:00
comunicapiv3/src/helpers/api_helper.rs

27 lines
828 B
Rust
Raw Normal View History

2020-05-23 09:00:53 +00:00
use crate::data::api_client::APIClient;
use crate::helpers::database;
use crate::helpers::database::QueryInfo;
2020-05-26 15:51:11 +00:00
use crate::constants::database_tables_names::SERVICES_TABLES;
2020-05-23 09:00:53 +00:00
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")?,
2020-05-23 12:08:22 +00:00
domain: res.get_optional_str("client_domain")?,
2020-05-23 09:00:53 +00:00
})
}
)
}