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