mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Get user page status
This commit is contained in:
parent
be4d1befcc
commit
eb3e6e9afa
@ -3,7 +3,7 @@
|
|||||||
//! @author Pierre Hubert
|
//! @author Pierre Hubert
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::data::user::User;
|
use crate::data::user::{User, UserPageStatus};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
@ -11,6 +11,8 @@ pub struct APIUserInfo {
|
|||||||
userID: i64,
|
userID: i64,
|
||||||
firstName: String,
|
firstName: String,
|
||||||
lastName: String,
|
lastName: String,
|
||||||
|
publicPage: bool,
|
||||||
|
openPage: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl APIUserInfo {
|
impl APIUserInfo {
|
||||||
@ -19,6 +21,8 @@ impl APIUserInfo {
|
|||||||
userID: info.id,
|
userID: info.id,
|
||||||
firstName: info.first_name,
|
firstName: info.first_name,
|
||||||
lastName: info.last_name,
|
lastName: info.last_name,
|
||||||
|
publicPage: info.status != UserPageStatus::PRIVATE,
|
||||||
|
openPage: info.status == UserPageStatus::OPEN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,13 @@
|
|||||||
|
|
||||||
pub type UserID = i64;
|
pub type UserID = i64;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum UserPageStatus {
|
||||||
|
OPEN,
|
||||||
|
PUBLIC,
|
||||||
|
PRIVATE
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: UserID,
|
pub id: UserID,
|
||||||
@ -11,4 +18,5 @@ pub struct User {
|
|||||||
pub password: String,
|
pub password: String,
|
||||||
pub first_name: String,
|
pub first_name: String,
|
||||||
pub last_name: String,
|
pub last_name: String,
|
||||||
|
pub status: UserPageStatus
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
use crate::data::error::ResultBoxError;
|
use crate::data::error::ResultBoxError;
|
||||||
use crate::data::user::{User, UserID};
|
use crate::data::user::{User, UserID, UserPageStatus};
|
||||||
use crate::helpers::database;
|
use crate::helpers::database;
|
||||||
use crate::database_structure::USERS_TABLE;
|
use crate::database_structure::USERS_TABLE;
|
||||||
|
|
||||||
@ -22,12 +22,24 @@ pub fn find_user_by_email(email: &str) -> ResultBoxError<User> {
|
|||||||
/// Execute query & return result
|
/// Execute query & return result
|
||||||
fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
||||||
database::query_row(query, |res| {
|
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 {
|
Ok(User {
|
||||||
id: res.get_int64("ID")?,
|
id: res.get_int64("ID")?,
|
||||||
email: res.get_str("mail")?,
|
email: res.get_str("mail")?,
|
||||||
password: res.get_str("password")?,
|
password: res.get_str("password")?,
|
||||||
first_name: res.get_str("prenom")?,
|
first_name: res.get_str("prenom")?,
|
||||||
last_name: res.get_str("nom")?,
|
last_name: res.get_str("nom")?,
|
||||||
|
status: page_status,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user