mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Get information about API client
This commit is contained in:
		
							
								
								
									
										27
									
								
								src/helpers/api_helper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/helpers/api_helper.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
use crate::data::api_client::APIClient;
 | 
			
		||||
use crate::helpers::database;
 | 
			
		||||
use crate::helpers::database::QueryInfo;
 | 
			
		||||
use crate::database_structure::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("domain")?,
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
@@ -125,6 +125,14 @@ impl<'a> RowResult<'a> {
 | 
			
		||||
            Some(s) => Ok(s)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get an optional string
 | 
			
		||||
    pub fn get_optional_str(&self, name: &str) -> Result<Option<String>, ExecError> {
 | 
			
		||||
        match self.find_col(name) {
 | 
			
		||||
            Ok(col) => Ok(self.row.get(col)),
 | 
			
		||||
            Err(_) => Ok(None),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1,3 @@
 | 
			
		||||
pub mod database;
 | 
			
		||||
pub mod database;
 | 
			
		||||
 | 
			
		||||
pub mod api_helper;
 | 
			
		||||
		Reference in New Issue
	
	Block a user