use async_graphql::{Context, Object}; use como_domain::projects::ProjectDto; use como_domain::users::User; use como_infrastructure::register::ServiceRegister; use uuid::Uuid; 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> { let user = ctx.data_unchecked::(); let items = ctx .data_unchecked::() .item_service .get_items( como_domain::item::queries::GetItemsQuery { project_id: self.id, }, user, ) .await? .iter() .map(|i| Item::from(i.clone())) .collect::>(); Ok(items) } } impl From for Project { fn from(dto: ProjectDto) -> Self { Self { id: dto.id, name: dto.name, } } }