feat: working projects and items
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,13 +1,47 @@
|
||||
use async_graphql::SimpleObject;
|
||||
use async_graphql::{Context, Object};
|
||||
use como_domain::projects::ProjectDto;
|
||||
use como_domain::users::User;
|
||||
use como_infrastructure::register::ServiceRegister;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(SimpleObject)]
|
||||
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 user = ctx.data_unchecked::<User>();
|
||||
|
||||
let items = ctx
|
||||
.data_unchecked::<ServiceRegister>()
|
||||
.item_service
|
||||
.get_items(
|
||||
como_domain::item::queries::GetItemsQuery {
|
||||
project_id: self.id,
|
||||
},
|
||||
user,
|
||||
)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|i| Item::from(i.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(items)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProjectDto> for Project {
|
||||
fn from(dto: ProjectDto) -> Self {
|
||||
Self {
|
||||
|
Reference in New Issue
Block a user