feat: import inventory services&domain obj to implement pantry #104
9 changed files with 85 additions and 58 deletions
|
@ -13,10 +13,9 @@ use uuid::Uuid;
|
|||
use super::errors::*;
|
||||
use super::InventoryDBPostgresAdapter;
|
||||
use crate::inventory::domain::events::InventoryEvent;
|
||||
use crate::inventory::domain::product_aggregate::{
|
||||
Currency, PriceBuilder, Product, ProductBuilder,
|
||||
};
|
||||
use crate::inventory::domain::product_aggregate::{Product, ProductBuilder};
|
||||
use crate::types::quantity::*;
|
||||
use crate::types::currency::*;
|
||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||
|
||||
pub const NEW_PRODUCT_NON_UUID: &str = "new_product_non_uuid-asdfa";
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::inventory::application::port::output::full_text_search::{
|
|||
add_product_to_store::*, errors::*,
|
||||
};
|
||||
use crate::inventory::domain::{category_aggregate::*, product_aggregate::*};
|
||||
use crate::types::currency::*;
|
||||
//use super::errors::*;
|
||||
|
||||
#[derive(
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::inventory::application::port::output::full_text_search::{
|
|||
add_product_to_store::*, errors::*,
|
||||
};
|
||||
use crate::inventory::domain::{category_aggregate::*, product_aggregate::*};
|
||||
use crate::types::currency::*;
|
||||
//use super::errors::*;
|
||||
|
||||
#[derive(
|
||||
|
|
|
@ -8,8 +8,8 @@ use derive_more::{Display, Error};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::product_aggregate::Price;
|
||||
use crate::types::quantity::*;
|
||||
use crate::types::currency::*;
|
||||
|
||||
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum AddProductCommandError {
|
||||
|
@ -88,10 +88,7 @@ impl UnvalidatedAddProductCommand {
|
|||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::{
|
||||
inventory::domain::product_aggregate::{Currency, PriceBuilder},
|
||||
utils::uuid::tests::UUID,
|
||||
};
|
||||
use crate::utils::uuid::tests::UUID;
|
||||
|
||||
pub fn get_command() -> AddProductCommand {
|
||||
let name = "foo";
|
||||
|
|
|
@ -7,8 +7,8 @@ use derive_getters::Getters;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::product_aggregate::Price;
|
||||
use crate::types::quantity::Quantity;
|
||||
use crate::types::currency::*;
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Builder, Serialize, Deserialize, Getters, Eq, PartialEq, Ord, PartialOrd,
|
||||
|
|
|
@ -2,13 +2,10 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use cqrs_es::Aggregate;
|
||||
use derive_builder::Builder;
|
||||
use derive_getters::Getters;
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -16,40 +13,7 @@ use super::{commands::InventoryCommand, events::InventoryEvent};
|
|||
use crate::inventory::application::services::errors::*;
|
||||
use crate::inventory::application::services::InventoryServicesInterface;
|
||||
use crate::types::quantity::Quantity;
|
||||
|
||||
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum Currency {
|
||||
#[display(fmt = "{}", INR)]
|
||||
INR,
|
||||
}
|
||||
|
||||
const INR: &str = "INR";
|
||||
|
||||
impl FromStr for Currency {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let s = s.trim();
|
||||
match s {
|
||||
INR => Ok(Self::INR),
|
||||
_ => Err("Currency unsupported".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Currency {
|
||||
fn default() -> Self {
|
||||
Self::INR
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||
)]
|
||||
pub struct Price {
|
||||
major: usize,
|
||||
minor: usize,
|
||||
currency: Currency,
|
||||
}
|
||||
use crate::types::currency::*;
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||
|
@ -127,6 +91,7 @@ impl Aggregate for Product {
|
|||
|
||||
#[cfg(test)]
|
||||
mod aggregate_tests {
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use cqrs_es::test::TestFramework;
|
||||
|
@ -198,9 +163,4 @@ mod aggregate_tests {
|
|||
|
||||
true
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn currency_to_string_from_str() {
|
||||
assert!(test_helper(Currency::INR, INR));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,15 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use derive_builder::Builder;
|
||||
use derive_getters::Getters;
|
||||
use derive_more::{Display, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::product_aggregate::{Price, Product};
|
||||
use super::product_aggregate::Product;
|
||||
use crate::types::quantity::Quantity;
|
||||
use crate::types::currency::*;
|
||||
|
||||
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum UpdateProductCommandError {
|
||||
|
@ -94,10 +93,7 @@ pub mod tests {
|
|||
use super::*;
|
||||
|
||||
use crate::types::quantity::*;
|
||||
use crate::{
|
||||
inventory::domain::product_aggregate::{Currency, PriceBuilder},
|
||||
utils::uuid::tests::UUID,
|
||||
};
|
||||
use crate::utils::uuid::tests::UUID;
|
||||
|
||||
pub fn get_command() -> UpdateProductCommand {
|
||||
let name = "foo";
|
||||
|
|
72
src/types/currency.rs
Normal file
72
src/types/currency.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use cqrs_es::Aggregate;
|
||||
use derive_builder::Builder;
|
||||
use derive_getters::Getters;
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum Currency {
|
||||
#[display(fmt = "{}", INR)]
|
||||
INR,
|
||||
}
|
||||
|
||||
const INR: &str = "INR";
|
||||
|
||||
impl FromStr for Currency {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let s = s.trim();
|
||||
match s {
|
||||
INR => Ok(Self::INR),
|
||||
_ => Err("Currency unsupported".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Currency {
|
||||
fn default() -> Self {
|
||||
Self::INR
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||
)]
|
||||
pub struct Price {
|
||||
major: usize,
|
||||
minor: usize,
|
||||
currency: Currency,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn test_helper<T>(t: T, str_value: &str) -> bool
|
||||
where
|
||||
T: ToString + FromStr + std::fmt::Debug + PartialEq,
|
||||
<T as FromStr>::Err: std::fmt::Debug,
|
||||
{
|
||||
println!("Testing type: {:?} against value {str_value}", t);
|
||||
assert_eq!(t.to_string(), str_value.to_string());
|
||||
|
||||
assert_eq!(T::from_str(str_value).unwrap(), t);
|
||||
|
||||
assert_eq!(T::from_str(t.to_string().as_str()).unwrap(), t,);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn currency_to_string_from_str() {
|
||||
assert!(test_helper(Currency::INR, INR));
|
||||
}
|
||||
}
|
|
@ -3,3 +3,4 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pub mod quantity;
|
||||
pub mod currency;
|
||||
|
|
Loading…
Reference in a new issue