49 lines
972 B
Rust
49 lines
972 B
Rust
use crate::common::*;
|
|
use async_graphql::{Context, Object};
|
|
use como_domain::projects::ProjectDto;
|
|
|
|
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<Vec<Item>> {
|
|
let items = item_service(ctx)
|
|
.get_items(
|
|
get_domain_context(ctx),
|
|
como_domain::item::queries::GetItemsQuery {
|
|
project_id: self.id,
|
|
},
|
|
)
|
|
.await?
|
|
.iter()
|
|
.map(|i| Item::from(i.clone()))
|
|
.collect::<Vec<_>>();
|
|
|
|
Ok(items)
|
|
}
|
|
}
|
|
|
|
impl From<ProjectDto> for Project {
|
|
fn from(dto: ProjectDto) -> Self {
|
|
Self {
|
|
id: dto.id,
|
|
name: dto.name,
|
|
}
|
|
}
|
|
}
|