2021-07-14 13:12:52 +00:00
|
|
|
use crate::{entities::*, errors::UserError, services::user_session::UserSession};
|
|
|
|
use flowy_dispatch::prelude::*;
|
|
|
|
use std::{convert::TryInto, sync::Arc};
|
|
|
|
|
|
|
|
pub async fn user_get_status_handler(
|
|
|
|
session: ModuleData<Arc<UserSession>>,
|
|
|
|
) -> ResponseResult<UserDetail, UserError> {
|
2021-07-16 15:18:12 +00:00
|
|
|
let user_detail = session.user_detail()?;
|
2021-07-14 13:12:52 +00:00
|
|
|
response_ok(user_detail)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn sign_out_handler(session: ModuleData<Arc<UserSession>>) -> Result<(), UserError> {
|
2021-07-16 15:18:12 +00:00
|
|
|
let _ = session.sign_out()?;
|
2021-07-14 13:12:52 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update_user_handler(
|
|
|
|
data: Data<UpdateUserRequest>,
|
|
|
|
session: ModuleData<Arc<UserSession>>,
|
|
|
|
) -> ResponseResult<UserDetail, UserError> {
|
|
|
|
let params: UpdateUserParams = data.into_inner().try_into()?;
|
2021-07-16 15:18:12 +00:00
|
|
|
let user_detail = session.update_user(params)?;
|
2021-07-14 13:12:52 +00:00
|
|
|
response_ok(user_detail)
|
|
|
|
}
|