mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Can get admin information
This commit is contained in:
parent
ef0845f075
commit
8f9021d8ef
26
src/api_data/admin/admin_info_api.rs
Normal file
26
src/api_data/admin/admin_info_api.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//! # Admin information API
|
||||||
|
//!
|
||||||
|
//! @author Pierre Hubert
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::data::admin::Admin;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct AdminInfoAPI {
|
||||||
|
id: u64,
|
||||||
|
name: String,
|
||||||
|
email: String,
|
||||||
|
time_create: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdminInfoAPI {
|
||||||
|
pub fn new(a: &Admin) -> Self {
|
||||||
|
Self {
|
||||||
|
id: a.id.id(),
|
||||||
|
name: a.name.clone(),
|
||||||
|
email: a.email.clone(),
|
||||||
|
time_create: a.time_create,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,4 +4,5 @@
|
|||||||
|
|
||||||
pub mod admin_auth_options;
|
pub mod admin_auth_options;
|
||||||
pub mod admin_auth_success;
|
pub mod admin_auth_success;
|
||||||
pub mod admin_id_api;
|
pub mod admin_id_api;
|
||||||
|
pub mod admin_info_api;
|
@ -5,6 +5,7 @@
|
|||||||
use crate::api_data::admin::admin_auth_options::AdminAuthOptions;
|
use crate::api_data::admin::admin_auth_options::AdminAuthOptions;
|
||||||
use crate::api_data::admin::admin_auth_success::AdminAuthSuccess;
|
use crate::api_data::admin::admin_auth_success::AdminAuthSuccess;
|
||||||
use crate::api_data::admin::admin_id_api::AdminIDAPI;
|
use crate::api_data::admin::admin_id_api::AdminIDAPI;
|
||||||
|
use crate::api_data::admin::admin_info_api::AdminInfoAPI;
|
||||||
use crate::data::base_request_handler::BaseRequestHandler;
|
use crate::data::base_request_handler::BaseRequestHandler;
|
||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||||||
use crate::helpers::{admin_access_token_helper, admin_account_helper};
|
use crate::helpers::{admin_access_token_helper, admin_account_helper};
|
||||||
@ -41,4 +42,11 @@ pub fn auth_with_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
/// Get current admin ID
|
/// Get current admin ID
|
||||||
pub fn get_admin_id(r: &mut HttpRequestHandler) -> RequestResult {
|
pub fn get_admin_id(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
r.set_response(AdminIDAPI::new(r.admin_id()?))
|
r.set_response(AdminIDAPI::new(r.admin_id()?))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get current admin information
|
||||||
|
pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let admin = admin_account_helper::find_admin_by_id(r.admin_id()?)?;
|
||||||
|
|
||||||
|
r.set_response(AdminInfoAPI::new(&admin))
|
||||||
}
|
}
|
@ -24,6 +24,12 @@ pub fn create(new_admin: &NewAdmin) -> Res<AdminID> {
|
|||||||
.map(|i| AdminID::new(i))
|
.map(|i| AdminID::new(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get admin information by ID
|
||||||
|
pub fn find_admin_by_id(id: AdminID) -> Res<Admin> {
|
||||||
|
database::QueryInfo::new(ADMIN_LIST_TABLE)
|
||||||
|
.cond_admin_id("id", id)
|
||||||
|
.query_row(db_to_admin)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get admin information by admin email address
|
/// Get admin information by admin email address
|
||||||
pub fn find_admin_by_email(email: &str) -> Res<Admin> {
|
pub fn find_admin_by_email(email: &str) -> Res<Admin> {
|
||||||
|
@ -171,6 +171,11 @@ impl QueryInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cond_admin_id(mut self, key: &str, val: AdminID) -> QueryInfo {
|
||||||
|
self.conditions.insert(key.to_string(), mysql::Value::from(val.id()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cond_group_id(mut self, key: &str, val: &GroupID) -> QueryInfo {
|
pub fn cond_group_id(mut self, key: &str, val: &GroupID) -> QueryInfo {
|
||||||
self.conditions.insert(key.to_string(), mysql::Value::from(val.id()));
|
self.conditions.insert(key.to_string(), mysql::Value::from(val.id()));
|
||||||
self
|
self
|
||||||
|
@ -350,5 +350,6 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
Route::limited_admin_post_without_login("/admin/accounts/auth_options", Box::new(admin_account_controller::get_auth_options), LimitPolicy::FAILURE(5)),
|
Route::limited_admin_post_without_login("/admin/accounts/auth_options", Box::new(admin_account_controller::get_auth_options), LimitPolicy::FAILURE(5)),
|
||||||
Route::limited_admin_post_without_login("/admin/accounts/auth_with_reset_token", Box::new(admin_account_controller::auth_with_reset_token), LimitPolicy::FAILURE(5)),
|
Route::limited_admin_post_without_login("/admin/accounts/auth_with_reset_token", Box::new(admin_account_controller::auth_with_reset_token), LimitPolicy::FAILURE(5)),
|
||||||
Route::admin_post("/admin/accounts/id", Box::new(admin_account_controller::get_admin_id)),
|
Route::admin_post("/admin/accounts/id", Box::new(admin_account_controller::get_admin_id)),
|
||||||
|
Route::admin_post("/admin/accounts/info", Box::new(admin_account_controller::get_admin_info)),
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user