2022-07-04 14:53:35 +08:00
|
|
|
use crate::errors::ErrorCode;
|
2021-11-07 21:45:18 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
2022-07-04 14:53:35 +08:00
|
|
|
use std::convert::TryInto;
|
2023-01-30 11:11:19 +08:00
|
|
|
use user_model::{SignInParams, SignUpParams, UserEmail, UserName, UserPassword};
|
2021-11-07 21:45:18 +08:00
|
|
|
|
2021-08-31 17:25:08 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-07-19 14:40:56 +08:00
|
|
|
pub struct SignInPayloadPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub password: String,
|
2021-11-06 22:35:45 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:40:56 +08:00
|
|
|
impl TryInto<SignInParams> for SignInPayloadPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
|
|
|
let email = UserEmail::parse(self.email)?;
|
|
|
|
let password = UserPassword::parse(self.password)?;
|
|
|
|
|
|
|
|
Ok(SignInParams {
|
|
|
|
email: email.0,
|
|
|
|
password: password.0,
|
|
|
|
name: self.name,
|
|
|
|
})
|
|
|
|
}
|
2021-08-31 17:25:08 +08:00
|
|
|
}
|
|
|
|
|
2021-07-05 21:23:13 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-07-19 14:40:56 +08:00
|
|
|
pub struct SignUpPayloadPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub password: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
}
|
2022-07-19 14:40:56 +08:00
|
|
|
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
|
|
|
let email = UserEmail::parse(self.email)?;
|
|
|
|
let password = UserPassword::parse(self.password)?;
|
|
|
|
let name = UserName::parse(self.name)?;
|
|
|
|
|
|
|
|
Ok(SignUpParams {
|
|
|
|
email: email.0,
|
|
|
|
name: name.0,
|
|
|
|
password: password.0,
|
|
|
|
})
|
|
|
|
}
|
2021-07-05 21:23:13 +08:00
|
|
|
}
|