68 lines
1.5 KiB
Rust
Raw Normal View History

use crate::{
entities::parser::*,
2021-07-25 08:13:59 +08:00
errors::{ErrorBuilder, UserErrCode, UserError},
};
2021-07-05 21:23:13 +08:00
use flowy_derive::ProtoBuf;
use std::convert::TryInto;
#[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-07-25 08:13:59 +08:00
let email = UserEmail::parse(self.email)
.map_err(|e| ErrorBuilder::new(UserErrCode::EmailInvalid).msg(e).build())?;
let password = UserPassword::parse(self.password).map_err(|e| {
2021-07-25 08:13:59 +08:00
ErrorBuilder::new(UserErrCode::PasswordInvalid)
.msg(e)
.build()
})?;
let name = UserName::parse(self.name).map_err(|e| {
2021-07-25 08:13:59 +08:00
ErrorBuilder::new(UserErrCode::UserNameInvalid)
.msg(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 uid: String,
2021-07-05 21:23:13 +08:00
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
pub email: String,
2021-07-05 21:23:13 +08:00
}