diff --git a/src/api_data/user_info.rs b/src/api_data/user_info.rs index cebb350..7e79eff 100644 --- a/src/api_data/user_info.rs +++ b/src/api_data/user_info.rs @@ -3,7 +3,7 @@ //! @author Pierre Hubert use serde::Serialize; -use crate::data::user::User; +use crate::data::user::{User, UserPageStatus}; #[derive(Serialize)] #[allow(non_snake_case)] @@ -11,6 +11,8 @@ pub struct APIUserInfo { userID: i64, firstName: String, lastName: String, + publicPage: bool, + openPage: bool, } impl APIUserInfo { @@ -19,6 +21,8 @@ impl APIUserInfo { userID: info.id, firstName: info.first_name, lastName: info.last_name, + publicPage: info.status != UserPageStatus::PRIVATE, + openPage: info.status == UserPageStatus::OPEN, } } } \ No newline at end of file diff --git a/src/data/user.rs b/src/data/user.rs index 400045c..bd33958 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -4,6 +4,13 @@ pub type UserID = i64; +#[derive(Debug, PartialEq)] +pub enum UserPageStatus { + OPEN, + PUBLIC, + PRIVATE +} + #[derive(Debug)] pub struct User { pub id: UserID, @@ -11,4 +18,5 @@ pub struct User { pub password: String, pub first_name: String, pub last_name: String, + pub status: UserPageStatus } \ No newline at end of file diff --git a/src/helpers/user_helper.rs b/src/helpers/user_helper.rs index a0ff4ad..2fee007 100644 --- a/src/helpers/user_helper.rs +++ b/src/helpers/user_helper.rs @@ -1,5 +1,5 @@ use crate::data::error::ResultBoxError; -use crate::data::user::{User, UserID}; +use crate::data::user::{User, UserID, UserPageStatus}; use crate::helpers::database; use crate::database_structure::USERS_TABLE; @@ -22,12 +22,24 @@ pub fn find_user_by_email(email: &str) -> ResultBoxError { /// Execute query & return result fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError { database::query_row(query, |res| { + + // Page status + let page_status = if res.get_int64("pageouverte")? == 1 { + UserPageStatus::OPEN + } else if res.get_int64("public")? == 1 { + UserPageStatus::PUBLIC + } else { + UserPageStatus::PRIVATE + }; + + Ok(User { id: res.get_int64("ID")?, email: res.get_str("mail")?, password: res.get_str("password")?, first_name: res.get_str("prenom")?, last_name: res.get_str("nom")?, + status: page_status, }) }) } \ No newline at end of file