feat: working projects and items
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -19,9 +19,11 @@ impl MutationRoot {
|
||||
ctx: &Context<'_>,
|
||||
item: CreateItemDto,
|
||||
) -> anyhow::Result<CreatedItem> {
|
||||
let user = ctx.data_unchecked::<User>();
|
||||
|
||||
let services_register = ctx.data_unchecked::<ServiceRegister>();
|
||||
|
||||
let created_item = services_register.item_service.add_item(item).await?;
|
||||
let created_item = services_register.item_service.add_item(item, user).await?;
|
||||
|
||||
Ok(CreatedItem {
|
||||
id: created_item.id,
|
||||
@@ -51,10 +53,12 @@ pub struct QueryRoot;
|
||||
#[Object]
|
||||
impl QueryRoot {
|
||||
async fn get_item(&self, ctx: &Context<'_>, query: GetItemQuery) -> anyhow::Result<Item> {
|
||||
let user = ctx.data_unchecked::<User>();
|
||||
|
||||
let item = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_item(query)
|
||||
.get_item(query, user)
|
||||
.await?;
|
||||
|
||||
Ok(Item::from(item))
|
||||
@@ -65,10 +69,12 @@ impl QueryRoot {
|
||||
ctx: &Context<'_>,
|
||||
query: GetItemsQuery,
|
||||
) -> anyhow::Result<Vec<Item>> {
|
||||
let user = ctx.data_unchecked::<User>();
|
||||
|
||||
let items = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_items(query)
|
||||
.get_items(query, user)
|
||||
.await?;
|
||||
|
||||
Ok(items.iter().map(|i| Item::from(i.clone())).collect())
|
||||
|
@@ -2,6 +2,7 @@ use async_graphql::{Context, Object};
|
||||
use como_domain::{
|
||||
item::{queries::GetItemQuery, ItemDto, ItemState},
|
||||
projects::queries::GetProjectQuery,
|
||||
users::User,
|
||||
};
|
||||
use como_infrastructure::register::ServiceRegister;
|
||||
use uuid::Uuid;
|
||||
@@ -15,10 +16,12 @@ pub struct CreatedItem {
|
||||
#[Object]
|
||||
impl CreatedItem {
|
||||
pub async fn item(&self, ctx: &Context<'_>) -> anyhow::Result<Item> {
|
||||
let user = ctx.data_unchecked::<User>();
|
||||
|
||||
let item = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_item(GetItemQuery { item_id: self.id })
|
||||
.get_item(GetItemQuery { item_id: self.id }, user)
|
||||
.await?;
|
||||
|
||||
Ok(item.into())
|
||||
@@ -30,6 +33,7 @@ pub struct Item {
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub state: ItemState,
|
||||
pub project_id: Uuid,
|
||||
}
|
||||
|
||||
#[Object]
|
||||
@@ -55,13 +59,16 @@ impl Item {
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.project_service
|
||||
.get_project(GetProjectQuery {
|
||||
item_id: Some(self.id),
|
||||
project_id: None,
|
||||
project_id: self.project_id,
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(project.into())
|
||||
}
|
||||
|
||||
pub async fn project_id(&self, _ctx: &Context<'_>) -> anyhow::Result<Uuid> {
|
||||
return Ok(self.project_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ItemDto> for Item {
|
||||
@@ -71,6 +78,7 @@ impl From<ItemDto> for Item {
|
||||
title: dto.title,
|
||||
description: dto.description,
|
||||
state: dto.state,
|
||||
project_id: dto.project_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,47 @@
|
||||
use async_graphql::SimpleObject;
|
||||
use async_graphql::{Context, Object};
|
||||
use como_domain::projects::ProjectDto;
|
||||
use como_domain::users::User;
|
||||
use como_infrastructure::register::ServiceRegister;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(SimpleObject)]
|
||||
use crate::items::Item;
|
||||
|
||||
pub struct Project {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[Object]
|
||||
impl Project {
|
||||
async fn id(&self) -> &Uuid {
|
||||
&self.id
|
||||
}
|
||||
|
||||
async fn name(&self) -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
||||
async fn items(&self, ctx: &Context<'_>) -> anyhow::Result<Vec<Item>> {
|
||||
let user = ctx.data_unchecked::<User>();
|
||||
|
||||
let items = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_items(
|
||||
como_domain::item::queries::GetItemsQuery {
|
||||
project_id: self.id,
|
||||
},
|
||||
user,
|
||||
)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|i| Item::from(i.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProjectDto> for Project {
|
||||
fn from(dto: ProjectDto) -> Self {
|
||||
Self {
|
||||
|
Reference in New Issue
Block a user