2021-06-29 15:21:25 +00:00
|
|
|
use crate::domain::{User, UserEmail, UserName};
|
|
|
|
use bytes::Bytes;
|
2021-07-01 07:40:26 +00:00
|
|
|
use flowy_sys::prelude::{response_ok, Data, FromBytes, ResponseResult, SystemError, ToBytes};
|
2021-06-29 15:21:25 +00:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
|
|
|
|
#[tracing::instrument(
|
|
|
|
name = "User check",
|
|
|
|
skip(data),
|
|
|
|
fields(
|
|
|
|
email = %data.email,
|
|
|
|
name = %data.name
|
|
|
|
)
|
|
|
|
)]
|
2021-07-01 07:40:26 +00:00
|
|
|
pub async fn user_check(data: Data<UserData>) -> ResponseResult<UserStatus, String> {
|
2021-06-30 15:11:27 +00:00
|
|
|
let user: User = data.into_inner().try_into()?;
|
|
|
|
|
2021-07-01 07:40:26 +00:00
|
|
|
response_ok(UserStatus { is_login: false })
|
2021-06-30 15:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Serialize)]
|
|
|
|
pub struct UserStatus {
|
|
|
|
is_login: bool,
|
|
|
|
}
|
2021-06-30 07:33:49 +00:00
|
|
|
|
2021-07-01 07:40:26 +00:00
|
|
|
impl FromBytes for UserData {
|
|
|
|
fn parse_from_bytes(bytes: &Vec<u8>) -> Result<UserData, SystemError> { unimplemented!() }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToBytes for UserStatus {
|
|
|
|
fn into_bytes(self) -> Result<Vec<u8>, SystemError> { unimplemented!() }
|
|
|
|
}
|
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
2021-06-29 15:21:25 +00:00
|
|
|
pub struct UserData {
|
|
|
|
name: String,
|
|
|
|
email: String,
|
|
|
|
}
|
|
|
|
|
2021-06-30 15:11:27 +00:00
|
|
|
impl UserData {
|
|
|
|
pub fn new(name: String, email: String) -> Self { Self { name, email } }
|
|
|
|
}
|
|
|
|
|
2021-06-29 15:21:25 +00:00
|
|
|
impl TryInto<User> for UserData {
|
|
|
|
type Error = String;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<User, Self::Error> {
|
|
|
|
let name = UserName::parse(self.name)?;
|
|
|
|
let email = UserEmail::parse(self.email)?;
|
|
|
|
Ok(User::new(name, email))
|
|
|
|
}
|
|
|
|
}
|