1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-03-14 09:52:37 +00:00
comunicapiv3/src/api_data/user_info.rs

39 lines
1.2 KiB
Rust
Raw Normal View History

2020-05-25 13:25:51 +02:00
//! API representation of user information
//!
//! @author Pierre Hubert
use serde::Serialize;
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,
accountImage: String,
2020-05-25 13:25:51 +02:00
}
impl APIUserInfo {
/// 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,
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,
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
}
}
/// 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
}