mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-28 14:38:52 +00:00
Get user page status
This commit is contained in:
parent
be4d1befcc
commit
eb3e6e9afa
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
@ -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<User> {
|
||||
/// Execute query & return result
|
||||
fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
||||
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,
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user