1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Ready to implement account image visibility

This commit is contained in:
2020-05-26 13:53:24 +02:00
parent d355f33cb0
commit cca7f02f8e
6 changed files with 47 additions and 7 deletions

View File

@ -3,7 +3,7 @@
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::user::{User, UserPageStatus};
use crate::data::user::{User, UserPageStatus, UserID};
#[derive(Serialize)]
#[allow(non_snake_case)]
@ -14,17 +14,26 @@ pub struct APIUserInfo {
publicPage: bool,
openPage: bool,
virtualDirectory: String,
accountImage: String,
}
impl APIUserInfo {
pub fn new(info: User) -> 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 {
APIUserInfo {
userID: info.id,
firstName: info.first_name,
lastName: info.last_name,
firstName: info.first_name.to_string(),
lastName: info.last_name.to_string(),
publicPage: info.status != UserPageStatus::PRIVATE,
openPage: info.status == UserPageStatus::OPEN,
virtualDirectory: info.virtual_directory.unwrap_or("".to_string())
virtualDirectory: info.virtual_directory.clone().unwrap_or(String::new()),
accountImage: APIUserInfo::get_account_image_url(user_id, info),
}
}
/// 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()
}
}