2022-07-04 06:53:35 +00:00
|
|
|
use crate::entities::*;
|
2022-01-11 05:34:45 +00:00
|
|
|
use crate::services::UserSession;
|
|
|
|
use flowy_error::FlowyError;
|
2021-11-19 06:38:11 +00:00
|
|
|
use lib_dispatch::prelude::*;
|
2021-07-09 15:31:44 +00:00
|
|
|
use std::{convert::TryInto, sync::Arc};
|
2021-06-29 15:21:25 +00:00
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
|
2022-04-12 03:13:35 +00:00
|
|
|
#[tracing::instrument(level = "debug", name = "sign_in", skip(data, session), fields(email = %data.email), err)]
|
2021-12-14 10:04:51 +00:00
|
|
|
pub async fn sign_in(
|
2022-07-19 06:40:56 +00:00
|
|
|
data: Data<SignInPayloadPB>,
|
2022-02-25 14:27:44 +00:00
|
|
|
session: AppData<Arc<UserSession>>,
|
2022-07-19 06:40:56 +00:00
|
|
|
) -> DataResult<UserProfilePB, FlowyError> {
|
2021-07-11 07:33:19 +00:00
|
|
|
let params: SignInParams = data.into_inner().try_into()?;
|
2021-09-04 08:53:58 +00:00
|
|
|
let user_profile = session.sign_in(params).await?;
|
|
|
|
data_result(user_profile)
|
2021-07-05 13:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(
|
2022-04-12 03:13:35 +00:00
|
|
|
level = "debug",
|
2021-07-25 00:13:59 +00:00
|
|
|
name = "sign_up",
|
2021-07-09 15:31:44 +00:00
|
|
|
skip(data, session),
|
2021-07-05 13:23:13 +00:00
|
|
|
fields(
|
2021-07-10 08:27:20 +00:00
|
|
|
email = %data.email,
|
|
|
|
name = %data.name,
|
2021-09-28 07:29:29 +00:00
|
|
|
),
|
|
|
|
err
|
2021-07-05 13:23:13 +00:00
|
|
|
)]
|
2021-12-14 10:04:51 +00:00
|
|
|
pub async fn sign_up(
|
2022-07-19 06:40:56 +00:00
|
|
|
data: Data<SignUpPayloadPB>,
|
2022-02-25 14:27:44 +00:00
|
|
|
session: AppData<Arc<UserSession>>,
|
2022-07-19 06:40:56 +00:00
|
|
|
) -> DataResult<UserProfilePB, FlowyError> {
|
2021-07-10 08:27:20 +00:00
|
|
|
let params: SignUpParams = data.into_inner().try_into()?;
|
2021-09-04 08:53:58 +00:00
|
|
|
let user_profile = session.sign_up(params).await?;
|
2021-09-03 08:43:03 +00:00
|
|
|
|
2021-09-04 08:53:58 +00:00
|
|
|
data_result(user_profile)
|
2021-07-11 07:33:19 +00:00
|
|
|
}
|