feat: with updated deps

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-06-04 14:42:38 +02:00
parent 534b2e4a23
commit 2604c5e301
21 changed files with 509 additions and 396 deletions

View File

@@ -6,31 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
como_core = { path = "../como_core" }
como_domain = { path = "../como_domain" }
como_infrastructure = { path = "../como_infrastructure" }
como_core.workspace = true
como_domain.workspace = true
como_infrastructure.workspace = true
async-graphql = "5.0.9"
async-graphql-axum = "5.0.9"
axum.workspace = true
axum-extra = { version = "*", features = ["cookie", "cookie-private"] }
axum-sessions = { version = "*" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.68"
tokio = { version = "1.20.1", features = ["full"] }
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
sqlx = { version = "0.6", features = [
"runtime-tokio-rustls",
"postgres",
"migrate",
"uuid",
"offline",
] }
anyhow = "1.0.60"
dotenv = "0.15.0"
tracing = "0.1.36"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tower-http = { version = "0.3.4", features = ["full"] }
argon2 = "0.4"
rand_core = { version = "0.6", features = ["std"] }
cookie = { version = "0.16", features = ["secure", "percent-encode"] }
anyhow.workspace = true
async-trait.workspace = true
async-graphql.workspace = true
uuid.workspace = true

View File

@@ -1,13 +1,12 @@
use crate::common::*;
use crate::items::{CreatedItem, Item};
use async_graphql::{Context, EmptySubscription, Object, Schema};
use como_domain::item::queries::{GetItemQuery, GetItemsQuery};
use como_domain::item::requests::CreateItemDto;
use como_domain::item::requests::{CreateItemDto, UpdateItemDto};
use como_domain::projects::mutation::CreateProjectMutation;
use como_domain::projects::queries::GetProjectQuery;
use como_domain::projects::ProjectDto;
use como_infrastructure::register::ServiceRegister;
pub type ComoSchema = Schema<QueryRoot, MutationRoot, EmptySubscription>;
pub struct MutationRoot;
@@ -19,13 +18,8 @@ impl MutationRoot {
ctx: &Context<'_>,
item: CreateItemDto,
) -> anyhow::Result<CreatedItem> {
let context = ctx.data_unchecked::<como_domain::Context>();
let services_register = ctx.data_unchecked::<ServiceRegister>();
let created_item = services_register
.item_service
.add_item(context, item)
let created_item = item_service(ctx)
.add_item(get_domain_context(ctx), item)
.await?;
Ok(CreatedItem {
@@ -38,17 +32,20 @@ impl MutationRoot {
ctx: &Context<'_>,
request: CreateProjectMutation,
) -> anyhow::Result<ProjectDto> {
let context = ctx.data_unchecked::<como_domain::Context>();
let services_register = ctx.data_unchecked::<ServiceRegister>();
let project = services_register
.project_service
.create_project(context, request)
let project = project_service(ctx)
.create_project(get_domain_context(ctx), request)
.await?;
Ok(project)
}
async fn update_item(&self, ctx: &Context<'_>, item: UpdateItemDto) -> anyhow::Result<Item> {
let updated_item = item_service(ctx)
.update_item(get_domain_context(ctx), item)
.await?;
Ok(updated_item.into())
}
}
pub struct QueryRoot;
@@ -56,12 +53,8 @@ pub struct QueryRoot;
#[Object]
impl QueryRoot {
async fn get_item(&self, ctx: &Context<'_>, query: GetItemQuery) -> anyhow::Result<Item> {
let context = ctx.data_unchecked::<como_domain::Context>();
let item = ctx
.data_unchecked::<ServiceRegister>()
.item_service
.get_item(context, query)
let item = item_service(ctx)
.get_item(get_domain_context(ctx), query)
.await?;
Ok(Item::from(item))
@@ -72,12 +65,8 @@ impl QueryRoot {
ctx: &Context<'_>,
query: GetItemsQuery,
) -> anyhow::Result<Vec<Item>> {
let context = ctx.data_unchecked::<como_domain::Context>();
let items = ctx
.data_unchecked::<ServiceRegister>()
.item_service
.get_items(context, query)
let items = item_service(ctx)
.get_items(get_domain_context(ctx), query)
.await?;
Ok(items.iter().map(|i| Item::from(i.clone())).collect())
@@ -89,20 +78,14 @@ impl QueryRoot {
ctx: &Context<'_>,
query: GetProjectQuery,
) -> anyhow::Result<ProjectDto> {
let context = ctx.data_unchecked::<como_domain::Context>();
ctx.data_unchecked::<ServiceRegister>()
.project_service
.get_project(context, query)
project_service(ctx)
.get_project(get_domain_context(ctx), query)
.await
}
async fn get_projects(&self, ctx: &Context<'_>) -> anyhow::Result<Vec<ProjectDto>> {
let context = ctx.data_unchecked::<como_domain::Context>();
ctx.data_unchecked::<ServiceRegister>()
.project_service
.get_projects(context)
project_service(ctx)
.get_projects(get_domain_context(ctx))
.await
}
}

View File

@@ -1,9 +1,9 @@
use crate::common::*;
use async_graphql::{Context, Object};
use como_domain::{
item::{queries::GetItemQuery, ItemDto, ItemState},
projects::queries::GetProjectQuery,
};
use como_infrastructure::register::ServiceRegister;
use uuid::Uuid;
use crate::projects::Project;
@@ -15,12 +15,8 @@ pub struct CreatedItem {
#[Object]
impl CreatedItem {
pub async fn item(&self, ctx: &Context<'_>) -> anyhow::Result<Item> {
let context = ctx.data_unchecked::<como_domain::Context>();
let item = ctx
.data_unchecked::<ServiceRegister>()
.item_service
.get_item(context, GetItemQuery { item_id: self.id })
let item = item_service(ctx)
.get_item(get_domain_context(ctx), GetItemQuery { item_id: self.id })
.await?;
Ok(item.into())
@@ -54,12 +50,9 @@ impl Item {
}
pub async fn project(&self, ctx: &Context<'_>) -> anyhow::Result<Project> {
let context = ctx.data_unchecked::<como_domain::Context>();
let project = ctx
.data_unchecked::<ServiceRegister>()
.project_service
let project = project_service(ctx)
.get_project(
context,
get_domain_context(ctx),
GetProjectQuery {
project_id: self.project_id,
},

View File

@@ -1,3 +1,33 @@
pub mod graphql;
mod items;
mod projects;
pub mod common {
use async_graphql::Context;
use como_core::items::DynItemService;
use como_core::projects::DynProjectService;
use como_infrastructure::register::ServiceRegister;
#[inline(always)]
pub(crate) fn get_domain_context<'a>(ctx: &Context<'a>) -> &'a como_domain::Context {
ctx.data_unchecked::<como_domain::Context>()
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) fn get_service_register<'a>(ctx: &Context<'a>) -> &'a ServiceRegister {
ctx.data_unchecked::<ServiceRegister>()
}
#[inline(always)]
pub(crate) fn project_service<'a>(ctx: &Context<'a>) -> DynProjectService {
ctx.data_unchecked::<ServiceRegister>()
.project_service
.clone()
}
#[inline(always)]
pub(crate) fn item_service<'a>(ctx: &Context<'a>) -> DynItemService {
ctx.data_unchecked::<ServiceRegister>().item_service.clone()
}
}

View File

@@ -1,7 +1,7 @@
use crate::common::*;
use async_graphql::{Context, Object};
use como_domain::projects::ProjectDto;
use como_infrastructure::register::ServiceRegister;
use uuid::Uuid;
use crate::items::Item;
@@ -22,13 +22,9 @@ impl Project {
}
async fn items(&self, ctx: &Context<'_>) -> anyhow::Result<Vec<Item>> {
let context = ctx.data_unchecked::<como_domain::Context>();
let items = ctx
.data_unchecked::<ServiceRegister>()
.item_service
let items = item_service(ctx)
.get_items(
context,
get_domain_context(ctx),
como_domain::item::queries::GetItemsQuery {
project_id: self.id,
},