2021-08-31 17:25:08 +08:00
|
|
|
use crate::{entities::parser::*, errors::*};
|
2021-07-05 21:23:13 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2021-08-31 17:25:08 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct SignInRequest {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:18:34 +08:00
|
|
|
#[derive(Default, ProtoBuf, Debug)]
|
2021-08-31 17:25:08 +08:00
|
|
|
pub struct SignInParams {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
|
|
pub struct SignInResponse {
|
|
|
|
#[pb(index = 1)]
|
2021-09-08 18:25:32 +08:00
|
|
|
pub user_id: String,
|
2021-08-31 17:25:08 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub token: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<SignInParams> for SignInRequest {
|
|
|
|
type Error = UserError;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
2021-09-16 12:35:55 +08:00
|
|
|
let email = UserEmail::parse(self.email).map_err(|e| UserError::code(e))?;
|
|
|
|
let password = UserPassword::parse(self.password).map_err(|e| UserError::code(e))?;
|
2021-08-31 17:25:08 +08:00
|
|
|
|
|
|
|
Ok(SignInParams {
|
|
|
|
email: email.0,
|
|
|
|
password: password.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 21:23:13 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2021-07-09 14:02:42 +08:00
|
|
|
pub struct SignUpRequest {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
2021-07-09 14:02:42 +08:00
|
|
|
impl TryInto<SignUpParams> for SignUpRequest {
|
2021-07-11 21:54:55 +08:00
|
|
|
type Error = UserError;
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2021-07-09 14:02:42 +08:00
|
|
|
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
2021-09-16 12:35:55 +08:00
|
|
|
let email = UserEmail::parse(self.email).map_err(|e| UserError::code(e))?;
|
|
|
|
let password = UserPassword::parse(self.password).map_err(|e| UserError::code(e))?;
|
|
|
|
let name = UserName::parse(self.name).map_err(|e| UserError::code(e))?;
|
2021-07-11 21:54:55 +08:00
|
|
|
|
2021-07-09 14:02:42 +08:00
|
|
|
Ok(SignUpParams {
|
2021-07-05 21:23:13 +08:00
|
|
|
email: email.0,
|
|
|
|
name: name.0,
|
|
|
|
password: password.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:18:34 +08:00
|
|
|
#[derive(ProtoBuf, Default, Debug)]
|
2021-07-09 14:02:42 +08:00
|
|
|
pub struct SignUpParams {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub password: String,
|
|
|
|
}
|
|
|
|
|
2021-07-09 14:02:42 +08:00
|
|
|
#[derive(ProtoBuf, Debug, Default)]
|
|
|
|
pub struct SignUpResponse {
|
2021-07-05 21:23:13 +08:00
|
|
|
#[pb(index = 1)]
|
2021-09-02 14:47:39 +08:00
|
|
|
pub user_id: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
|
2021-08-20 11:52:45 +08:00
|
|
|
#[pb(index = 2)]
|
2021-08-20 14:38:03 +08:00
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2021-08-20 11:52:45 +08:00
|
|
|
pub email: String,
|
2021-08-31 17:56:38 +08:00
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub token: String,
|
2021-07-05 21:23:13 +08:00
|
|
|
}
|