2022-10-04 22:39:57 +02:00
|
|
|
use async_graphql::{Context, Object};
|
|
|
|
use como_domain::{
|
|
|
|
item::{queries::GetItemQuery, ItemDto, ItemState},
|
|
|
|
projects::queries::GetProjectQuery,
|
2023-05-28 17:17:22 +02:00
|
|
|
users::User,
|
2022-10-04 22:39:57 +02:00
|
|
|
};
|
|
|
|
use como_infrastructure::register::ServiceRegister;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use crate::projects::Project;
|
|
|
|
|
|
|
|
pub struct CreatedItem {
|
|
|
|
pub id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Object]
|
|
|
|
impl CreatedItem {
|
|
|
|
pub async fn item(&self, ctx: &Context<'_>) -> anyhow::Result<Item> {
|
2023-05-28 17:17:22 +02:00
|
|
|
let user = ctx.data_unchecked::<User>();
|
|
|
|
|
2022-10-04 22:39:57 +02:00
|
|
|
let item = ctx
|
|
|
|
.data_unchecked::<ServiceRegister>()
|
|
|
|
.item_service
|
2023-05-28 17:17:22 +02:00
|
|
|
.get_item(GetItemQuery { item_id: self.id }, user)
|
2022-10-04 22:39:57 +02:00
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(item.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Item {
|
|
|
|
pub id: Uuid,
|
|
|
|
pub title: String,
|
|
|
|
pub description: Option<String>,
|
|
|
|
pub state: ItemState,
|
2023-05-28 17:17:22 +02:00
|
|
|
pub project_id: Uuid,
|
2022-10-04 22:39:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Object]
|
|
|
|
impl Item {
|
|
|
|
pub async fn id(&self, _ctx: &Context<'_>) -> anyhow::Result<Uuid> {
|
|
|
|
return Ok(self.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn title(&self, _ctx: &Context<'_>) -> anyhow::Result<String> {
|
|
|
|
return Ok(self.title.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn description(&self, _ctx: &Context<'_>) -> anyhow::Result<Option<String>> {
|
|
|
|
return Ok(self.description.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn state(&self, _ctx: &Context<'_>) -> anyhow::Result<ItemState> {
|
|
|
|
return Ok(self.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn project(&self, ctx: &Context<'_>) -> anyhow::Result<Project> {
|
|
|
|
let project = ctx
|
|
|
|
.data_unchecked::<ServiceRegister>()
|
|
|
|
.project_service
|
|
|
|
.get_project(GetProjectQuery {
|
2023-05-28 17:17:22 +02:00
|
|
|
project_id: self.project_id,
|
2022-10-04 22:39:57 +02:00
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(project.into())
|
|
|
|
}
|
2023-05-28 17:17:22 +02:00
|
|
|
|
|
|
|
pub async fn project_id(&self, _ctx: &Context<'_>) -> anyhow::Result<Uuid> {
|
|
|
|
return Ok(self.project_id);
|
|
|
|
}
|
2022-10-04 22:39:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ItemDto> for Item {
|
|
|
|
fn from(dto: ItemDto) -> Self {
|
|
|
|
Self {
|
|
|
|
id: dto.id,
|
|
|
|
title: dto.title,
|
|
|
|
description: dto.description,
|
|
|
|
state: dto.state,
|
2023-05-28 17:17:22 +02:00
|
|
|
project_id: dto.project_id,
|
2022-10-04 22:39:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|