feat: with create project

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-05-28 16:25:25 +02:00
parent c81a988061
commit 6dc0c24443
8 changed files with 92 additions and 40 deletions

View File

@@ -2,9 +2,9 @@ use std::{collections::HashMap, sync::Arc};
use axum::async_trait;
use como_core::projects::ProjectService;
use como_domain::projects::{
queries::{GetProjectQuery, GetProjectsQuery},
ProjectDto,
use como_domain::{
projects::{mutation::CreateProjectMutation, queries::GetProjectQuery, ProjectDto},
users::User,
};
use tokio::sync::Mutex;
@@ -21,7 +21,14 @@ impl ProjectService for DefaultProjectService {
async fn get_project(&self, _query: GetProjectQuery) -> anyhow::Result<ProjectDto> {
todo!()
}
async fn get_projects(&self, _query: GetProjectsQuery) -> anyhow::Result<Vec<ProjectDto>> {
async fn get_projects(&self, user: &User) -> anyhow::Result<Vec<ProjectDto>> {
todo!()
}
async fn create_project(
&self,
name: CreateProjectMutation,
user: &User,
) -> anyhow::Result<ProjectDto> {
todo!()
}
}
@@ -51,7 +58,31 @@ impl ProjectService for MemoryProjectService {
Err(anyhow::anyhow!("could not find project"))
}
}
async fn get_projects(&self, _query: GetProjectsQuery) -> anyhow::Result<Vec<ProjectDto>> {
todo!()
async fn get_projects(&self, user: &User) -> anyhow::Result<Vec<ProjectDto>> {
Ok(self
.project_store
.lock()
.await
.values()
.filter(|p| p.user_id == user.id)
.cloned()
.collect::<_>())
}
async fn create_project(
&self,
mutation: CreateProjectMutation,
user: &User,
) -> anyhow::Result<ProjectDto> {
let mut ps = self.project_store.lock().await;
let project = ProjectDto {
id: uuid::Uuid::new_v4(),
name: mutation.name,
description: None,
user_id: user.id.clone(),
};
ps.insert(project.id.to_string(), project.clone());
Ok(project)
}
}