use async_graphql::{Context, EmptySubscription, Object, Schema, SimpleObject}; use como_domain::item::{requests::CreateItemDto, responses::CreatedItemDto, ItemState}; use como_infrastructure::register::ServiceRegister; use uuid::Uuid; pub type CibusSchema = Schema; pub struct MutationRoot; #[Object] impl MutationRoot { async fn login( &self, ctx: &Context<'_>, username: String, password: String, ) -> anyhow::Result { let service_register = ctx.data_unchecked::(); let valid = service_register .user_service .validate_user(username, password) .await?; let returnvalid = match valid { Some(..) => true, None => false, }; Ok(returnvalid) } async fn register( &self, ctx: &Context<'_>, username: String, password: String, ) -> anyhow::Result { let service_register = ctx.data_unchecked::(); let user_id = service_register .user_service .add_user(username, password) .await?; Ok(user_id) } async fn create_item( &self, ctx: &Context<'_>, item: CreateItemDto, ) -> anyhow::Result { let services_register = ctx.data_unchecked::(); let created_item = services_register.item_service.add_item(item).await?; Ok(created_item) } } pub struct QueryRoot; #[Object] impl QueryRoot { async fn hello(&self, ctx: &Context<'_>) -> String { "hello".into() } }