AppFlowy/rust-lib/flowy-user/src/handlers/user_handler.rs

25 lines
828 B
Rust
Raw Normal View History

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> {
let user_detail = session.current_user_detail()?;
response_ok(user_detail)
}
pub async fn sign_out_handler(session: ModuleData<Arc<UserSession>>) -> Result<(), UserError> {
let _ = session.sign_out().await?;
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()?;
let user_detail = session.update_user(params).await?;
response_ok(user_detail)
}