add start
This commit is contained in:
@@ -1,13 +1,49 @@
|
||||
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject};
|
||||
use async_graphql::{Context, EmptySubscription, Object, Schema, SimpleObject};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub type CibusSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
|
||||
use crate::services::users_service::UserService;
|
||||
|
||||
pub type CibusSchema = Schema<QueryRoot, MutationRoot, EmptySubscription>;
|
||||
|
||||
pub struct MutationRoot;
|
||||
|
||||
#[Object]
|
||||
impl MutationRoot {
|
||||
async fn login(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
username: String,
|
||||
password: String,
|
||||
) -> anyhow::Result<bool> {
|
||||
let user_service = ctx.data_unchecked::<UserService>();
|
||||
|
||||
let valid = user_service.validate_user(username, password).await?;
|
||||
|
||||
Ok(match valid {
|
||||
Some(..) => true,
|
||||
None => false,
|
||||
})
|
||||
}
|
||||
|
||||
async fn register(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
username: String,
|
||||
password: String,
|
||||
) -> anyhow::Result<String> {
|
||||
let user_service = ctx.data_unchecked::<UserService>();
|
||||
|
||||
let user_id = user_service.add_user(username, password).await?;
|
||||
|
||||
Ok(user_id.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct QueryRoot;
|
||||
|
||||
#[Object]
|
||||
impl QueryRoot {
|
||||
async fn get_upcoming(&self, ctx: &Context<'_>) -> Vec<Event> {
|
||||
async fn get_upcoming(&self, _ctx: &Context<'_>) -> Vec<Event> {
|
||||
vec![Event::new(
|
||||
None,
|
||||
"Some-name".into(),
|
||||
|
Reference in New Issue
Block a user