use crate::domain::handler::BackendHandler; use juniper::{graphql_object, FieldResult, GraphQLInputObject}; use super::api::Context; #[derive(PartialEq, Eq, Debug)] /// The top-level GraphQL mutation type. pub struct Mutation { _phantom: std::marker::PhantomData>, } impl Mutation { pub fn new() -> Self { Self { _phantom: std::marker::PhantomData, } } } #[derive(PartialEq, Eq, Debug, GraphQLInputObject)] /// The details required to create a user. pub struct UserInput { id: String, email: String, display_name: Option, first_name: Option, last_name: Option, } #[graphql_object(context = Context)] impl Mutation { async fn create_user( context: &Context, user: UserInput, ) -> FieldResult> { if !context.validation_result.is_admin { return Err("Unauthorized user creation".into()); } context .handler .create_user(lldap_model::CreateUserRequest { user_id: user.id.clone(), email: user.email, display_name: user.display_name, first_name: user.first_name, last_name: user.last_name, }) .await?; Ok(context .handler .get_user_details(&user.id) .await .map(Into::into)?) } }