feat: cqrs_es scaffolding
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline failed
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2024-07-13 19:37:30 +05:30
parent 126ab58aa0
commit c56d13b196
Signed by: realaravinth
GPG key ID: F8F50389936984FF
13 changed files with 125 additions and 14 deletions

10
Cargo.lock generated
View file

@ -3228,6 +3228,7 @@ dependencies = [
"tokio-stream",
"tracing",
"url",
"uuid",
"webpki-roots 0.25.4",
]
@ -3310,6 +3311,7 @@ dependencies = [
"thiserror",
"time",
"tracing",
"uuid",
"whoami",
]
@ -3349,6 +3351,7 @@ dependencies = [
"thiserror",
"time",
"tracing",
"uuid",
"whoami",
]
@ -3374,6 +3377,7 @@ dependencies = [
"tracing",
"url",
"urlencoding",
"uuid",
]
[[package]]
@ -3952,11 +3956,12 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "uuid"
version = "1.8.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
dependencies = [
"getrandom",
"serde",
]
[[package]]
@ -4062,6 +4067,7 @@ dependencies = [
"tracing",
"tracing-actix-web",
"url",
"uuid",
"validator 0.18.1",
]

View file

@ -28,12 +28,13 @@ rand = "0.8.5"
rust-embed = { version = "8.4.0", features = ["include-exclude"] }
serde = { version = "1.0.201", features = ["derive"] }
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"
time = { version = "0.3.36", features = ["serde"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-actix-web = "0.7.10"
url = { version = "2.5.0", features = ["serde"] }
uuid = { version = "1.10.0", features = ["v4", "serde"] }
validator = { version = "0.18.1", features = ["derive"] }
[dev-dependencies]

View 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);

View file

@ -0,0 +1 @@
pub mod postgres;

View file

@ -1,3 +1,5 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
mod db;

View file

@ -2,5 +2,5 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
mod port;
mod services;
pub mod port;
pub mod services;

View file

@ -2,5 +2,5 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
mod input;
mod output;
pub mod input;
pub mod output;

View file

@ -2,6 +2,6 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod category_exists;
//pub mod category_exists;
pub mod errors;
pub mod store_id_exists;

View file

@ -1,3 +1,5 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod db;

View file

@ -8,26 +8,26 @@ use mockall::*;
pub mod errors;
// services
pub mod add_category_service;
//pub mod add_category_service;
pub mod add_store_service;
#[automock]
pub trait InventoryServicesInterface: Send + Sync {
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)]
pub struct InventoryServices {
add_store: add_store_service::AddStoreServiceObj,
add_category: add_category_service::AddCategoryServiceObj,
// add_category: add_category_service::AddCategoryServiceObj,
}
impl InventoryServicesInterface for InventoryServices {
fn add_store(&self) -> add_store_service::AddStoreServiceObj {
self.add_store.clone()
}
fn add_category(&self) -> add_category_service::AddCategoryServiceObj {
self.add_category.clone()
}
// fn add_category(&self) -> add_category_service::AddCategoryServiceObj {
// self.add_category.clone()
// }
}

View 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),
}

View 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()
}
}

View file

@ -1,3 +1,19 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// 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;