2020-05-25 13:25:51 +02:00
|
|
|
//! API representation of user information
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
use serde::Serialize;
|
|
|
|
|
2020-05-26 13:53:24 +02:00
|
|
|
use crate::data::user::{User, UserPageStatus, UserID};
|
2020-05-25 13:25:51 +02:00
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub struct APIUserInfo {
|
|
|
|
userID: i64,
|
|
|
|
firstName: String,
|
|
|
|
lastName: String,
|
2020-05-26 13:15:39 +02:00
|
|
|
publicPage: bool,
|
|
|
|
openPage: bool,
|
2020-05-26 13:18:38 +02:00
|
|
|
virtualDirectory: String,
|
2020-05-26 13:53:24 +02:00
|
|
|
accountImage: String,
|
2020-05-25 13:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl APIUserInfo {
|
2020-05-26 13:53:24 +02:00
|
|
|
/// Construct a new API user instance. Note: `user_id` is the ID of the user who makes the
|
|
|
|
/// requests, not the user whose we return information about!
|
|
|
|
pub fn new(user_id: Option<UserID>, info: &User) -> APIUserInfo {
|
2020-05-25 13:25:51 +02:00
|
|
|
APIUserInfo {
|
|
|
|
userID: info.id,
|
2020-05-26 13:53:24 +02:00
|
|
|
firstName: info.first_name.to_string(),
|
|
|
|
lastName: info.last_name.to_string(),
|
2020-05-26 13:15:39 +02:00
|
|
|
publicPage: info.status != UserPageStatus::PRIVATE,
|
|
|
|
openPage: info.status == UserPageStatus::OPEN,
|
2020-05-26 13:53:24 +02:00
|
|
|
virtualDirectory: info.virtual_directory.clone().unwrap_or(String::new()),
|
|
|
|
accountImage: APIUserInfo::get_account_image_url(user_id, info),
|
2020-05-25 13:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-26 13:53:24 +02:00
|
|
|
|
|
|
|
/// Get the URL of a specific user account image
|
|
|
|
pub fn get_account_image_url(user_id: Option<UserID>, user: &User) -> String {
|
|
|
|
"do it".to_string()
|
|
|
|
}
|
2020-05-25 13:25:51 +02:00
|
|
|
}
|