2023-05-28 17:17:22 +02:00
|
|
|
use async_graphql::{Context, Object};
|
2022-10-04 22:39:57 +02:00
|
|
|
use como_domain::projects::ProjectDto;
|
2023-06-04 11:02:51 +02:00
|
|
|
|
2023-05-28 17:17:22 +02:00
|
|
|
use como_infrastructure::register::ServiceRegister;
|
2022-10-04 22:39:57 +02:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2023-05-28 17:17:22 +02:00
|
|
|
use crate::items::Item;
|
|
|
|
|
2022-10-04 22:39:57 +02:00
|
|
|
pub struct Project {
|
|
|
|
pub id: Uuid,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
2023-05-28 17:17:22 +02:00
|
|
|
#[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>> {
|
2023-06-04 11:02:51 +02:00
|
|
|
let context = ctx.data_unchecked::<como_domain::Context>();
|
2023-05-28 17:17:22 +02:00
|
|
|
|
|
|
|
let items = ctx
|
|
|
|
.data_unchecked::<ServiceRegister>()
|
|
|
|
.item_service
|
|
|
|
.get_items(
|
2023-06-04 11:02:51 +02:00
|
|
|
context,
|
2023-05-28 17:17:22 +02:00
|
|
|
como_domain::item::queries::GetItemsQuery {
|
|
|
|
project_id: self.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await?
|
|
|
|
.iter()
|
|
|
|
.map(|i| Item::from(i.clone()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
Ok(items)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 22:39:57 +02:00
|
|
|
impl From<ProjectDto> for Project {
|
|
|
|
fn from(dto: ProjectDto) -> Self {
|
|
|
|
Self {
|
|
|
|
id: dto.id,
|
|
|
|
name: dto.name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|