80
crates/como_gql/src/items.rs
Normal file
80
crates/como_gql/src/items.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use crate::common::*;
|
||||
use async_graphql::{Context, Object};
|
||||
use como_domain::{
|
||||
item::{queries::GetItemQuery, ItemDto, ItemState},
|
||||
projects::queries::GetProjectQuery,
|
||||
};
|
||||
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> {
|
||||
let item = item_service(ctx)
|
||||
.get_item(get_domain_context(ctx), GetItemQuery { item_id: self.id })
|
||||
.await?;
|
||||
|
||||
Ok(item.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Item {
|
||||
pub id: Uuid,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub state: ItemState,
|
||||
pub project_id: Uuid,
|
||||
}
|
||||
|
||||
#[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 = project_service(ctx)
|
||||
.get_project(
|
||||
get_domain_context(ctx),
|
||||
GetProjectQuery {
|
||||
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 {
|
||||
fn from(dto: ItemDto) -> Self {
|
||||
Self {
|
||||
id: dto.id,
|
||||
title: dto.title,
|
||||
description: dto.description,
|
||||
state: dto.state,
|
||||
project_id: dto.project_id,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user