feat: working projects and items
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -5,11 +5,14 @@ use std::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use como_core::items::ItemService;
|
||||
use como_domain::item::{
|
||||
queries::{GetItemQuery, GetItemsQuery},
|
||||
requests::CreateItemDto,
|
||||
responses::CreatedItemDto,
|
||||
ItemDto,
|
||||
use como_domain::{
|
||||
item::{
|
||||
queries::{GetItemQuery, GetItemsQuery},
|
||||
requests::CreateItemDto,
|
||||
responses::CreatedItemDto,
|
||||
ItemDto,
|
||||
},
|
||||
users::User,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -23,15 +26,15 @@ impl DefaultItemService {
|
||||
|
||||
#[async_trait]
|
||||
impl ItemService for DefaultItemService {
|
||||
async fn add_item(&self, _item: CreateItemDto) -> anyhow::Result<CreatedItemDto> {
|
||||
async fn add_item(&self, _item: CreateItemDto, user: &User) -> anyhow::Result<CreatedItemDto> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn get_item(&self, _query: GetItemQuery) -> anyhow::Result<ItemDto> {
|
||||
async fn get_item(&self, _query: GetItemQuery, user: &User) -> anyhow::Result<ItemDto> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn get_items(&self, _query: GetItemsQuery) -> anyhow::Result<Vec<ItemDto>> {
|
||||
async fn get_items(&self, _query: GetItemsQuery, user: &User) -> anyhow::Result<Vec<ItemDto>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -50,13 +53,18 @@ impl MemoryItemService {
|
||||
|
||||
#[async_trait]
|
||||
impl ItemService for MemoryItemService {
|
||||
async fn add_item(&self, create_item: CreateItemDto) -> anyhow::Result<CreatedItemDto> {
|
||||
async fn add_item(
|
||||
&self,
|
||||
create_item: CreateItemDto,
|
||||
user: &User,
|
||||
) -> anyhow::Result<CreatedItemDto> {
|
||||
if let Ok(mut item_store) = self.item_store.lock() {
|
||||
let item = ItemDto {
|
||||
id: Uuid::new_v4(),
|
||||
title: create_item.name,
|
||||
description: None,
|
||||
description: create_item.description,
|
||||
state: como_domain::item::ItemState::Created,
|
||||
project_id: create_item.project_id,
|
||||
};
|
||||
|
||||
item_store.insert(item.id.to_string(), item.clone());
|
||||
@@ -67,7 +75,7 @@ impl ItemService for MemoryItemService {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_item(&self, query: GetItemQuery) -> anyhow::Result<ItemDto> {
|
||||
async fn get_item(&self, query: GetItemQuery, user: &User) -> anyhow::Result<ItemDto> {
|
||||
if let Ok(item_store) = self.item_store.lock() {
|
||||
let item = item_store
|
||||
.get(&query.item_id.to_string())
|
||||
@@ -78,7 +86,7 @@ impl ItemService for MemoryItemService {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_items(&self, _query: GetItemsQuery) -> anyhow::Result<Vec<ItemDto>> {
|
||||
async fn get_items(&self, _query: GetItemsQuery, user: &User) -> anyhow::Result<Vec<ItemDto>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@@ -49,14 +49,10 @@ impl MemoryProjectService {
|
||||
impl ProjectService for MemoryProjectService {
|
||||
async fn get_project(&self, query: GetProjectQuery) -> anyhow::Result<ProjectDto> {
|
||||
let ps = self.project_store.lock().await;
|
||||
if let Some(item_id) = query.item_id {
|
||||
Ok(ps
|
||||
.get(&item_id.to_string())
|
||||
.ok_or(anyhow::anyhow!("could not find project"))?
|
||||
.clone())
|
||||
} else {
|
||||
Err(anyhow::anyhow!("could not find project"))
|
||||
}
|
||||
Ok(ps
|
||||
.get(&query.project_id.to_string())
|
||||
.ok_or(anyhow::anyhow!("could not find project"))?
|
||||
.clone())
|
||||
}
|
||||
async fn get_projects(&self, user: &User) -> anyhow::Result<Vec<ProjectDto>> {
|
||||
Ok(self
|
||||
|
Reference in New Issue
Block a user