2020-05-25 13:25:51 +02:00
|
|
|
//! API representation of user information
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
use serde::Serialize;
|
|
|
|
|
2020-05-26 13:15:39 +02:00
|
|
|
use crate::data::user::{User, UserPageStatus};
|
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-25 13:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl APIUserInfo {
|
|
|
|
pub fn new(info: User) -> APIUserInfo {
|
|
|
|
APIUserInfo {
|
|
|
|
userID: info.id,
|
|
|
|
firstName: info.first_name,
|
|
|
|
lastName: info.last_name,
|
2020-05-26 13:15:39 +02:00
|
|
|
publicPage: info.status != UserPageStatus::PRIVATE,
|
|
|
|
openPage: info.status == UserPageStatus::OPEN,
|
2020-05-26 13:18:38 +02:00
|
|
|
virtualDirectory: info.virtual_directory.unwrap_or("".to_string())
|
2020-05-25 13:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|