105 lines
2.2 KiB
Rust
Raw Normal View History

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,
}
#[derive(Default, ProtoBuf)]
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)]
pub uid: String,
#[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> {
let email = UserEmail::parse(self.email).map_err(|e| ErrorBuilder::new(e).build())?;
let password = UserPassword::parse(self.password).map_err(|e| ErrorBuilder::new(e).build())?;
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)]
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,
}
impl TryInto<SignUpParams> for SignUpRequest {
type Error = UserError;
2021-07-05 21:23:13 +08:00
fn try_into(self) -> Result<SignUpParams, Self::Error> {
2021-08-21 17:17:54 +08:00
let email = UserEmail::parse(self.email).map_err(|e| ErrorBuilder::new(e).build())?;
let password = UserPassword::parse(self.password).map_err(|e| ErrorBuilder::new(e).build())?;
2021-08-21 17:17:54 +08:00
let name = UserName::parse(self.name).map_err(|e| ErrorBuilder::new(e).build())?;
Ok(SignUpParams {
2021-07-05 21:23:13 +08:00
email: email.0,
name: name.0,
password: password.0,
})
}
}
#[derive(ProtoBuf, Default)]
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,
}
#[derive(ProtoBuf, Debug, Default)]
pub struct SignUpResponse {
2021-07-05 21:23:13 +08:00
#[pb(index = 1)]
pub user_id: String,
2021-07-05 21:23:13 +08:00
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
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
}