feat: with create project

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-05-28 16:25:25 +02:00
parent c81a988061
commit 6dc0c24443
8 changed files with 92 additions and 40 deletions

View File

@@ -1,18 +1,12 @@
use async_graphql::{Context, EmptySubscription, Object, Schema};
use como_domain::{
item::{
queries::{GetItemQuery, GetItemsQuery},
requests::CreateItemDto,
},
projects::{
queries::{GetProjectQuery, GetProjectsQuery},
ProjectDto,
},
};
use como_infrastructure::register::ServiceRegister;
use crate::items::{CreatedItem, Item};
use async_graphql::{Context, EmptySubscription, Object, Schema};
use como_domain::item::queries::{GetItemQuery, GetItemsQuery};
use como_domain::item::requests::CreateItemDto;
use como_domain::projects::mutation::CreateProjectMutation;
use como_domain::projects::queries::GetProjectQuery;
use como_domain::projects::ProjectDto;
use como_domain::users::User;
use como_infrastructure::register::ServiceRegister;
pub type ComoSchema = Schema<QueryRoot, MutationRoot, EmptySubscription>;
@@ -33,13 +27,29 @@ impl MutationRoot {
id: created_item.id,
})
}
async fn create_project(
&self,
ctx: &Context<'_>,
request: CreateProjectMutation,
) -> anyhow::Result<ProjectDto> {
let user = ctx.data_unchecked::<User>();
let services_register = ctx.data_unchecked::<ServiceRegister>();
let project = services_register
.project_service
.create_project(request, user)
.await?;
Ok(project)
}
}
pub struct QueryRoot;
#[Object]
impl QueryRoot {
// Items
async fn get_item(&self, ctx: &Context<'_>, query: GetItemQuery) -> anyhow::Result<Item> {
let item = ctx
.data_unchecked::<ServiceRegister>()
@@ -76,14 +86,12 @@ impl QueryRoot {
.await
}
async fn get_projects(
&self,
ctx: &Context<'_>,
query: GetProjectsQuery,
) -> anyhow::Result<Vec<ProjectDto>> {
async fn get_projects(&self, ctx: &Context<'_>) -> anyhow::Result<Vec<ProjectDto>> {
let user = ctx.data_unchecked::<User>();
ctx.data_unchecked::<ServiceRegister>()
.project_service
.get_projects(query)
.get_projects(user)
.await
}
}