2020-06-23 16:55:23 +00:00
|
|
|
//! # Global search result API
|
|
|
|
//!
|
|
|
|
//! @author Pierre
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::data::global_search_result::GlobalSearchResult;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct GlobalSearchResultAPI {
|
|
|
|
kind: String,
|
|
|
|
id: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GlobalSearchResultAPI {
|
|
|
|
/// Construct new entry
|
|
|
|
pub fn new(res: &GlobalSearchResult) -> GlobalSearchResultAPI {
|
|
|
|
match res {
|
|
|
|
GlobalSearchResult::User(user_id) => GlobalSearchResultAPI {
|
|
|
|
kind: "user".to_string(),
|
2020-06-25 08:08:34 +00:00
|
|
|
id: user_id.id(),
|
2020-06-23 16:55:23 +00:00
|
|
|
},
|
|
|
|
GlobalSearchResult::Group(group_id) => GlobalSearchResultAPI {
|
|
|
|
kind: "group".to_string(),
|
|
|
|
id: group_id.id(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct a list of results
|
|
|
|
pub fn for_list(l: &Vec<GlobalSearchResult>) -> Vec<GlobalSearchResultAPI> {
|
|
|
|
l.iter()
|
|
|
|
.map(|f| Self::new(f))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|