feat: cqrs_es scaffolding
This commit is contained in:
parent
126ab58aa0
commit
c56d13b196
13 changed files with 125 additions and 14 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -3228,6 +3228,7 @@ dependencies = [
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
|
"uuid",
|
||||||
"webpki-roots 0.25.4",
|
"webpki-roots 0.25.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3310,6 +3311,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"uuid",
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3349,6 +3351,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"uuid",
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3374,6 +3377,7 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3952,11 +3956,12 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.8.0"
|
version = "1.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
|
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4062,6 +4067,7 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-actix-web",
|
"tracing-actix-web",
|
||||||
"url",
|
"url",
|
||||||
|
"uuid",
|
||||||
"validator 0.18.1",
|
"validator 0.18.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,13 @@ rand = "0.8.5"
|
||||||
rust-embed = { version = "8.4.0", features = ["include-exclude"] }
|
rust-embed = { version = "8.4.0", features = ["include-exclude"] }
|
||||||
serde = { version = "1.0.201", features = ["derive"] }
|
serde = { version = "1.0.201", features = ["derive"] }
|
||||||
serde_json = "1.0.117"
|
serde_json = "1.0.117"
|
||||||
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "postgres", "time"] }
|
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
|
||||||
tera = "1.19.1"
|
tera = "1.19.1"
|
||||||
time = { version = "0.3.36", features = ["serde"] }
|
time = { version = "0.3.36", features = ["serde"] }
|
||||||
tracing = { version = "0.1.40", features = ["log"] }
|
tracing = { version = "0.1.40", features = ["log"] }
|
||||||
tracing-actix-web = "0.7.10"
|
tracing-actix-web = "0.7.10"
|
||||||
url = { version = "2.5.0", features = ["serde"] }
|
url = { version = "2.5.0", features = ["serde"] }
|
||||||
|
uuid = { version = "1.10.0", features = ["v4", "serde"] }
|
||||||
validator = { version = "0.18.1", features = ["derive"] }
|
validator = { version = "0.18.1", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
32
migrations/20240713080804_cqrs_inventory_store_query.sql
Normal file
32
migrations/20240713080804_cqrs_inventory_store_query.sql
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
--- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
--
|
||||||
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS categoty_events
|
||||||
|
(
|
||||||
|
aggregate_type text NOT NULL,
|
||||||
|
aggregate_id text NOT NULL,
|
||||||
|
sequence bigint CHECK (sequence >= 0) NOT NULL,
|
||||||
|
event_type text NOT NULL,
|
||||||
|
event_version text NOT NULL,
|
||||||
|
payload json NOT NULL,
|
||||||
|
metadata json NOT NULL,
|
||||||
|
timestamp timestamp with time zone DEFAULT (CURRENT_TIMESTAMP),
|
||||||
|
PRIMARY KEY (aggregate_type, aggregate_id, sequence)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cqrs_inventory_store_query
|
||||||
|
(
|
||||||
|
view_id text NOT NULL,
|
||||||
|
version bigint CHECK (version >= 0) NOT NULL,
|
||||||
|
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
address TEXT,
|
||||||
|
owner TEXT NOT NULL,
|
||||||
|
store_id UUID NOT NULL UNIQUE,
|
||||||
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
|
PRIMARY KEY (view_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS store_store_id_index ON cqrs_inventory_store_query (store_id);
|
1
src/inventory/adapters/output/db/mod.rs
Normal file
1
src/inventory/adapters/output/db/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod postgres;
|
|
@ -1,3 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
mod db;
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
mod port;
|
pub mod port;
|
||||||
mod services;
|
pub mod services;
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
mod input;
|
pub mod input;
|
||||||
mod output;
|
pub mod output;
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
pub mod category_exists;
|
//pub mod category_exists;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod store_id_exists;
|
pub mod store_id_exists;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
pub mod db;
|
||||||
|
|
|
@ -8,26 +8,26 @@ use mockall::*;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
|
||||||
// services
|
// services
|
||||||
pub mod add_category_service;
|
//pub mod add_category_service;
|
||||||
pub mod add_store_service;
|
pub mod add_store_service;
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
pub trait InventoryServicesInterface: Send + Sync {
|
pub trait InventoryServicesInterface: Send + Sync {
|
||||||
fn add_store(&self) -> add_store_service::AddStoreServiceObj;
|
fn add_store(&self) -> add_store_service::AddStoreServiceObj;
|
||||||
fn add_category(&self) -> add_category_service::AddCategoryServiceObj;
|
// fn add_category(&self) -> add_category_service::AddCategoryServiceObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
#[derive(Clone, Builder)]
|
||||||
pub struct InventoryServices {
|
pub struct InventoryServices {
|
||||||
add_store: add_store_service::AddStoreServiceObj,
|
add_store: add_store_service::AddStoreServiceObj,
|
||||||
add_category: add_category_service::AddCategoryServiceObj,
|
// add_category: add_category_service::AddCategoryServiceObj,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InventoryServicesInterface for InventoryServices {
|
impl InventoryServicesInterface for InventoryServices {
|
||||||
fn add_store(&self) -> add_store_service::AddStoreServiceObj {
|
fn add_store(&self) -> add_store_service::AddStoreServiceObj {
|
||||||
self.add_store.clone()
|
self.add_store.clone()
|
||||||
}
|
}
|
||||||
fn add_category(&self) -> add_category_service::AddCategoryServiceObj {
|
// fn add_category(&self) -> add_category_service::AddCategoryServiceObj {
|
||||||
self.add_category.clone()
|
// self.add_category.clone()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
17
src/inventory/domain/commands.rs
Normal file
17
src/inventory/domain/commands.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use mockall::predicate::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
// add_category_command::AddCategoryCommand,
|
||||||
|
add_store_command::AddStoreCommand,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
|
pub enum InventoryCommand {
|
||||||
|
//AddCategory(AddCategoryCommand),
|
||||||
|
AddStore(AddStoreCommand),
|
||||||
|
}
|
34
src/inventory/domain/events.rs
Normal file
34
src/inventory/domain/events.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use cqrs_es::DomainEvent;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
// category_added_event::*,
|
||||||
|
store_added_event::StoreAddedEvent,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
|
pub enum InventoryEvent {
|
||||||
|
// CategoryAdded(CategoryAddedEvent),
|
||||||
|
StoreAdded(StoreAddedEvent),
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: define password type that takes string and converts to hash
|
||||||
|
|
||||||
|
impl DomainEvent for InventoryEvent {
|
||||||
|
fn event_version(&self) -> String {
|
||||||
|
"1.0".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn event_type(&self) -> String {
|
||||||
|
let e: &str = match self {
|
||||||
|
// InventoryEvent::CategoryAdded { .. } => "InventoryCategoryAdded",
|
||||||
|
InventoryEvent::StoreAdded { .. } => "InventoryStoredded",
|
||||||
|
};
|
||||||
|
|
||||||
|
e.to_string()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,19 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
// aggregates
|
||||||
|
//pub mod money_aggregate;
|
||||||
|
//pub mod product_aggregate;
|
||||||
|
//pub mod stock_aggregate;
|
||||||
|
pub mod store_aggregate;
|
||||||
|
|
||||||
|
// commands
|
||||||
|
//pub mod add_category_command;
|
||||||
|
pub mod add_store_command;
|
||||||
|
pub mod commands;
|
||||||
|
|
||||||
|
// events
|
||||||
|
//pub mod category_added_event;
|
||||||
|
pub mod events;
|
||||||
|
pub mod store_added_event;
|
||||||
|
|
Loading…
Reference in a new issue