2021-07-11 07:33:19 +00:00
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct QueryUserDetailParams {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub token: String,
|
|
|
|
}
|
|
|
|
|
2021-07-11 07:33:19 +00:00
|
|
|
#[derive(Debug, ProtoBuf_Enum)]
|
|
|
|
pub enum UserStatus {
|
|
|
|
Unknown = 0,
|
|
|
|
Login = 1,
|
|
|
|
Expired = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for UserStatus {
|
|
|
|
fn default() -> Self { UserStatus::Unknown }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Debug)]
|
|
|
|
pub struct UserDetail {
|
|
|
|
#[pb(index = 1)]
|
2021-07-14 13:12:52 +00:00
|
|
|
pub id: String,
|
2021-07-11 07:33:19 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2021-07-14 13:12:52 +00:00
|
|
|
pub email: String,
|
2021-07-11 07:33:19 +00:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2021-07-14 13:12:52 +00:00
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
2021-08-31 09:25:08 +00:00
|
|
|
pub token: String,
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
use crate::{
|
|
|
|
entities::parser::{UserEmail, UserId, UserName, UserPassword},
|
|
|
|
errors::{ErrorBuilder, ErrorCode, UserError},
|
|
|
|
sql_tables::UserTable,
|
|
|
|
};
|
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2021-07-19 09:37:58 +00:00
|
|
|
impl std::convert::From<UserTable> for UserDetail {
|
|
|
|
fn from(user: UserTable) -> Self {
|
2021-07-11 07:33:19 +00:00
|
|
|
UserDetail {
|
2021-07-14 13:12:52 +00:00
|
|
|
id: user.id,
|
2021-07-11 07:33:19 +00:00
|
|
|
email: user.email,
|
|
|
|
name: user.name,
|
2021-08-31 09:25:08 +00:00
|
|
|
token: user.token,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct UpdateUserRequest {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub email: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub password: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateUserRequest {
|
|
|
|
pub fn new(id: &str) -> Self {
|
|
|
|
Self {
|
|
|
|
id: id.to_owned(),
|
|
|
|
..Default::default()
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-31 09:25:08 +00:00
|
|
|
|
|
|
|
pub fn name(mut self, name: &str) -> Self {
|
|
|
|
self.name = Some(name.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn email(mut self, email: &str) -> Self {
|
|
|
|
self.email = Some(email.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn password(mut self, password: &str) -> Self {
|
|
|
|
self.password = Some(password.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct UpdateUserParams {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub email: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub password: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<UpdateUserParams> for UpdateUserRequest {
|
|
|
|
type Error = UserError;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<UpdateUserParams, Self::Error> {
|
|
|
|
let id = UserId::parse(self.id)
|
|
|
|
.map_err(|e| ErrorBuilder::new(ErrorCode::UserIdInvalid).msg(e).build())?
|
|
|
|
.0;
|
|
|
|
|
|
|
|
let name = match self.name {
|
|
|
|
None => None,
|
|
|
|
Some(name) => Some(
|
|
|
|
UserName::parse(name)
|
|
|
|
.map_err(|e| ErrorBuilder::new(e).build())?
|
|
|
|
.0,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
let email = match self.email {
|
|
|
|
None => None,
|
|
|
|
Some(email) => Some(
|
|
|
|
UserEmail::parse(email)
|
|
|
|
.map_err(|e| ErrorBuilder::new(e).build())?
|
|
|
|
.0,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
let password = match self.password {
|
|
|
|
None => None,
|
|
|
|
Some(password) => Some(
|
|
|
|
UserPassword::parse(password)
|
|
|
|
.map_err(|e| ErrorBuilder::new(e).build())?
|
|
|
|
.0,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(UpdateUserParams {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
email,
|
|
|
|
password,
|
|
|
|
})
|
|
|
|
}
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|