with memory db
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
use async_graphql::{Context, EmptySubscription, Object, Schema};
|
||||
|
||||
use como_domain::item::{requests::CreateItemDto, responses::CreatedItemDto};
|
||||
use como_domain::{
|
||||
item::{
|
||||
queries::{GetItemQuery, GetItemsQuery},
|
||||
requests::CreateItemDto,
|
||||
responses::CreatedItemDto,
|
||||
ItemDto,
|
||||
},
|
||||
projects::{
|
||||
queries::{GetProjectQuery, GetProjectsQuery},
|
||||
ProjectDto,
|
||||
},
|
||||
};
|
||||
use como_infrastructure::register::ServiceRegister;
|
||||
|
||||
use crate::items::{CreatedItem, Item};
|
||||
|
||||
pub type ComoSchema = Schema<QueryRoot, MutationRoot, EmptySubscription>;
|
||||
|
||||
pub struct MutationRoot;
|
||||
@@ -49,12 +62,14 @@ impl MutationRoot {
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
item: CreateItemDto,
|
||||
) -> anyhow::Result<CreatedItemDto> {
|
||||
) -> anyhow::Result<CreatedItem> {
|
||||
let services_register = ctx.data_unchecked::<ServiceRegister>();
|
||||
|
||||
let created_item = services_register.item_service.add_item(item).await?;
|
||||
|
||||
Ok(created_item)
|
||||
Ok(CreatedItem {
|
||||
id: created_item.id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +77,51 @@ pub struct QueryRoot;
|
||||
|
||||
#[Object]
|
||||
impl QueryRoot {
|
||||
async fn hello(&self, _ctx: &Context<'_>) -> String {
|
||||
"hello".into()
|
||||
// Items
|
||||
async fn get_item(&self, ctx: &Context<'_>, query: GetItemQuery) -> anyhow::Result<Item> {
|
||||
let item = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_item(query)
|
||||
.await?;
|
||||
|
||||
Ok(Item::from(item))
|
||||
}
|
||||
|
||||
async fn get_items(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
query: GetItemsQuery,
|
||||
) -> anyhow::Result<Vec<Item>> {
|
||||
let items = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_items(query)
|
||||
.await?;
|
||||
|
||||
Ok(items.iter().map(|i| Item::from(i.clone())).collect())
|
||||
}
|
||||
|
||||
// Projects
|
||||
async fn get_project(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
query: GetProjectQuery,
|
||||
) -> anyhow::Result<ProjectDto> {
|
||||
ctx.data_unchecked::<ServiceRegister>()
|
||||
.project_service
|
||||
.get_project(query)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_projects(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
query: GetProjectsQuery,
|
||||
) -> anyhow::Result<Vec<ProjectDto>> {
|
||||
ctx.data_unchecked::<ServiceRegister>()
|
||||
.project_service
|
||||
.get_projects(query)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user