chore: clippy lints #44
38 changed files with 187 additions and 261 deletions
|
@ -42,7 +42,7 @@ mod tests {
|
||||||
|
|
||||||
let msg = CreateSecretMsgBuilder::default()
|
let msg = CreateSecretMsgBuilder::default()
|
||||||
.secret("secret".into())
|
.secret("secret".into())
|
||||||
.user_id(UUID.clone())
|
.user_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ mod tests {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
let msg = VerifySecretExistsMsgBuilder::default()
|
let msg = VerifySecretExistsMsgBuilder::default()
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.secret(secret.into())
|
.secret(secret.into())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -59,7 +59,7 @@ mod tests {
|
||||||
|
|
||||||
let create_msg = CreateSecretMsgBuilder::default()
|
let create_msg = CreateSecretMsgBuilder::default()
|
||||||
.secret(secret.into())
|
.secret(secret.into())
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.create_verification_secret(create_msg).await.unwrap();
|
db.create_verification_secret(create_msg).await.unwrap();
|
||||||
|
|
|
@ -60,7 +60,7 @@ mod tests {
|
||||||
|
|
||||||
let create_msg = CreateSecretMsgBuilder::default()
|
let create_msg = CreateSecretMsgBuilder::default()
|
||||||
.secret(secret.into())
|
.secret(secret.into())
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl View<User> for UserView {
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
self.first_name = val.first_name().into();
|
self.first_name = val.first_name().into();
|
||||||
self.last_name = val.last_name().into();
|
self.last_name = val.last_name().into();
|
||||||
self.user_id = val.user_id().clone();
|
self.user_id = *val.user_id();
|
||||||
}
|
}
|
||||||
UserEvent::UserDeleted => self.deleted = true,
|
UserEvent::UserDeleted => self.deleted = true,
|
||||||
UserEvent::Loggedin(_) => (),
|
UserEvent::Loggedin(_) => (),
|
||||||
|
|
|
@ -56,7 +56,7 @@ mod tests {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
let msg = VerifySecretExistsMsgBuilder::default()
|
let msg = VerifySecretExistsMsgBuilder::default()
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.secret(secret.into())
|
.secret(secret.into())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -66,7 +66,7 @@ mod tests {
|
||||||
|
|
||||||
let create_msg = CreateSecretMsgBuilder::default()
|
let create_msg = CreateSecretMsgBuilder::default()
|
||||||
.secret(secret.into())
|
.secret(secret.into())
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
db.create_verification_secret(create_msg).await.unwrap();
|
db.create_verification_secret(create_msg).await.unwrap();
|
||||||
|
|
|
@ -29,7 +29,7 @@ mod tests {
|
||||||
fn test_cmd() {
|
fn test_cmd() {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let secret = "asdfasdf";
|
let secret = "asdfasdf";
|
||||||
let cmd = MarkUserVerifiedCommand::new(user_id.clone(), secret.into()).unwrap();
|
let cmd = MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap();
|
||||||
assert_eq!(cmd.user_id(), &user_id);
|
assert_eq!(cmd.user_id(), &user_id);
|
||||||
assert_eq!(cmd.secret(), secret);
|
assert_eq!(cmd.secret(), secret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl MarkUserVerifiedUseCase for MarkUserVerifiedService {
|
||||||
cmd: command::MarkUserVerifiedCommand,
|
cmd: command::MarkUserVerifiedCommand,
|
||||||
) -> IdentityResult<()> {
|
) -> IdentityResult<()> {
|
||||||
let msg = VerifySecretExistsMsgBuilder::default()
|
let msg = VerifySecretExistsMsgBuilder::default()
|
||||||
.user_id(cmd.user_id().clone())
|
.user_id(*cmd.user_id())
|
||||||
.secret(cmd.secret().into())
|
.secret(cmd.secret().into())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -54,7 +54,7 @@ mod tests {
|
||||||
async fn test_service() {
|
async fn test_service() {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let secret = "password";
|
let secret = "password";
|
||||||
let cmd = command::MarkUserVerifiedCommand::new(user_id.clone(), secret.into()).unwrap();
|
let cmd = command::MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap();
|
||||||
|
|
||||||
// happy case
|
// happy case
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl RegisterUserUseCase for RegisterUserService {
|
||||||
.create_verification_secret(
|
.create_verification_secret(
|
||||||
CreateSecretMsgBuilder::default()
|
CreateSecretMsgBuilder::default()
|
||||||
.secret(secret.clone())
|
.secret(secret.clone())
|
||||||
.user_id(user_id.clone())
|
.user_id(user_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
@ -103,7 +103,7 @@ mod tests {
|
||||||
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
|
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
|
||||||
.first_name(username.into())
|
.first_name(username.into())
|
||||||
.last_name(username.into())
|
.last_name(username.into())
|
||||||
.email(email.into())
|
.email(email)
|
||||||
.password(password.into())
|
.password(password.into())
|
||||||
.confirm_password(password.into())
|
.confirm_password(password.into())
|
||||||
.build()
|
.build()
|
||||||
|
@ -151,7 +151,7 @@ mod tests {
|
||||||
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
|
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
|
||||||
.first_name(username.into())
|
.first_name(username.into())
|
||||||
.last_name(username.into())
|
.last_name(username.into())
|
||||||
.email(email.into())
|
.email(email)
|
||||||
.password(password.into())
|
.password(password.into())
|
||||||
.confirm_password(password.into())
|
.confirm_password(password.into())
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -41,7 +41,7 @@ mod tests {
|
||||||
fn test_cmd() {
|
fn test_cmd() {
|
||||||
let config = argon2_creds::Config::default();
|
let config = argon2_creds::Config::default();
|
||||||
ResendVerificationEmailCommand::new(
|
ResendVerificationEmailCommand::new(
|
||||||
UUID.clone(),
|
UUID,
|
||||||
"john".into(),
|
"john".into(),
|
||||||
"realaravinth@example.com".into(),
|
"realaravinth@example.com".into(),
|
||||||
&config,
|
&config,
|
||||||
|
@ -49,13 +49,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ResendVerificationEmailCommand::new(
|
ResendVerificationEmailCommand::new(UUID, "john".into(), "john".into(), &config).err(),
|
||||||
UUID.clone(),
|
|
||||||
"john".into(),
|
|
||||||
"john".into(),
|
|
||||||
&config
|
|
||||||
)
|
|
||||||
.err(),
|
|
||||||
Some(IdentityCommandError::BadEmail)
|
Some(IdentityCommandError::BadEmail)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,11 @@ mod tests {
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service() {
|
async fn test_service() {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let email = format!("john@example.com");
|
let email = "john@example.com".to_string();
|
||||||
let secret = "asdfasdf";
|
let secret = "asdfasdf";
|
||||||
let config = argon2_creds::Config::default();
|
let config = argon2_creds::Config::default();
|
||||||
let cmd = command::ResendVerificationEmailCommand::new(
|
let cmd = command::ResendVerificationEmailCommand::new(
|
||||||
UUID.clone(),
|
UUID,
|
||||||
"john".into(),
|
"john".into(),
|
||||||
email.clone(),
|
email.clone(),
|
||||||
&config,
|
&config,
|
||||||
|
@ -88,11 +88,11 @@ mod tests {
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service_email_exists() {
|
async fn test_service_email_exists() {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let email = format!("john@example.com");
|
let email = "john@example.com".to_string();
|
||||||
let secret = "asdfasdf";
|
let secret = "asdfasdf";
|
||||||
let config = argon2_creds::Config::default();
|
let config = argon2_creds::Config::default();
|
||||||
let cmd = command::ResendVerificationEmailCommand::new(
|
let cmd = command::ResendVerificationEmailCommand::new(
|
||||||
UUID.clone(),
|
UUID,
|
||||||
"john".into(),
|
"john".into(),
|
||||||
email.clone(),
|
email.clone(),
|
||||||
&config,
|
&config,
|
||||||
|
|
|
@ -44,7 +44,7 @@ mod tests {
|
||||||
.email_verified(false)
|
.email_verified(false)
|
||||||
.is_admin(true)
|
.is_admin(true)
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.user_id(UUID.clone())
|
.user_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
@ -61,7 +61,7 @@ mod tests {
|
||||||
.is_admin(false)
|
.is_admin(false)
|
||||||
.email_verified(false)
|
.email_verified(false)
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.user_id(UUID.clone())
|
.user_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,7 +38,7 @@ mod tests {
|
||||||
.email_verified(false)
|
.email_verified(false)
|
||||||
.is_admin(true)
|
.is_admin(true)
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.user_id(UUID.clone())
|
.user_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,12 @@ mod tests {
|
||||||
let password = "adsfasdfasd";
|
let password = "adsfasdfasd";
|
||||||
let first_name = "john";
|
let first_name = "john";
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let new_email = format!("newemail@example.com");
|
let new_email = "newemail@example.com".to_string();
|
||||||
let hashed_password = config.password(password).unwrap();
|
let hashed_password = config.password(password).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
UpdateEmailCommand::new(
|
UpdateEmailCommand::new(
|
||||||
new_email.clone(),
|
new_email.clone(),
|
||||||
user_id.clone(),
|
user_id,
|
||||||
first_name.into(),
|
first_name.into(),
|
||||||
password.into(),
|
password.into(),
|
||||||
&hashed_password,
|
&hashed_password,
|
||||||
|
@ -69,7 +69,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
UpdateEmailCommand::new(
|
UpdateEmailCommand::new(
|
||||||
user_id.to_string(),
|
user_id.to_string(),
|
||||||
user_id.clone(),
|
user_id,
|
||||||
first_name.into(),
|
first_name.into(),
|
||||||
password.into(),
|
password.into(),
|
||||||
&hashed_password,
|
&hashed_password,
|
||||||
|
@ -83,7 +83,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
UpdateEmailCommand::new(
|
UpdateEmailCommand::new(
|
||||||
new_email.to_string(),
|
new_email.to_string(),
|
||||||
user_id.clone(),
|
user_id,
|
||||||
first_name.into(),
|
first_name.into(),
|
||||||
first_name.into(),
|
first_name.into(),
|
||||||
&hashed_password,
|
&hashed_password,
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl UpdateEmailUseCase for UpdateEmailService {
|
||||||
.create_verification_secret(
|
.create_verification_secret(
|
||||||
CreateSecretMsgBuilder::default()
|
CreateSecretMsgBuilder::default()
|
||||||
.secret(secret.clone())
|
.secret(secret.clone())
|
||||||
.user_id(cmd.user_id().clone())
|
.user_id(*cmd.user_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
@ -71,14 +71,14 @@ mod tests {
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service() {
|
async fn test_service() {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let new_email = format!("john@example.com");
|
let new_email = "john@example.com".to_string();
|
||||||
let password = "password";
|
let password = "password";
|
||||||
let config = argon2_creds::Config::default();
|
let config = argon2_creds::Config::default();
|
||||||
let hashed_password = config.password(password).unwrap();
|
let hashed_password = config.password(password).unwrap();
|
||||||
|
|
||||||
let cmd = command::UpdateEmailCommand::new(
|
let cmd = command::UpdateEmailCommand::new(
|
||||||
new_email.clone(),
|
new_email.clone(),
|
||||||
user_id.clone(),
|
user_id,
|
||||||
"john".into(),
|
"john".into(),
|
||||||
password.into(),
|
password.into(),
|
||||||
&hashed_password,
|
&hashed_password,
|
||||||
|
|
|
@ -55,7 +55,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.hashed_new_passowrd,
|
.hashed_new_passowrd,
|
||||||
new_password.into(),
|
new_password,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ mod tests {
|
||||||
username.into(),
|
username.into(),
|
||||||
password.into(),
|
password.into(),
|
||||||
new_password.clone(),
|
new_password.clone(),
|
||||||
new_password.into(),
|
new_password,
|
||||||
&hashed_password,
|
&hashed_password,
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
|
|
|
@ -142,12 +142,12 @@ impl Aggregate for User {
|
||||||
UserEvent::UserRegistered(e) => {
|
UserEvent::UserRegistered(e) => {
|
||||||
self.first_name = e.first_name().into();
|
self.first_name = e.first_name().into();
|
||||||
self.last_name = e.last_name().into();
|
self.last_name = e.last_name().into();
|
||||||
self.user_id = e.user_id().clone();
|
self.user_id = *e.user_id();
|
||||||
self.email = e.email().into();
|
self.email = e.email().into();
|
||||||
self.hashed_password = e.hashed_password().into();
|
self.hashed_password = e.hashed_password().into();
|
||||||
self.is_admin = e.is_admin().clone();
|
self.is_admin = *e.is_admin();
|
||||||
self.email_verified = e.email_verified().clone();
|
self.email_verified = *e.email_verified();
|
||||||
self.is_verified = e.is_verified().clone();
|
self.is_verified = *e.is_verified();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
UserEvent::UserDeleted => {
|
UserEvent::UserDeleted => {
|
||||||
|
|
|
@ -32,15 +32,12 @@ pub struct CategoryView {
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Category> for CategoryView {
|
impl View<Category> for CategoryView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Category>) {
|
fn update(&mut self, event: &EventEnvelope<Category>) {
|
||||||
match &event.payload {
|
if let InventoryEvent::CategoryAdded(val) = &event.payload {
|
||||||
InventoryEvent::CategoryAdded(val) => {
|
self.name = val.name().into();
|
||||||
self.name = val.name().into();
|
self.description = val.description().clone();
|
||||||
self.description = val.description().clone();
|
self.category_id = *val.category_id();
|
||||||
self.category_id = val.category_id().clone();
|
self.store_id = *val.store_id();
|
||||||
self.store_id = val.store_id().clone();
|
self.deleted = false;
|
||||||
self.deleted = false;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +184,7 @@ impl Query<Category> for SimpleLoggingQuery {
|
||||||
impl Query<Category> for InventoryDBPostgresAdapter {
|
impl Query<Category> for InventoryDBPostgresAdapter {
|
||||||
async fn dispatch(&self, category_id: &str, events: &[EventEnvelope<Category>]) {
|
async fn dispatch(&self, category_id: &str, events: &[EventEnvelope<Category>]) {
|
||||||
let res = self
|
let res = self
|
||||||
.load_with_context(&category_id)
|
.load_with_context(category_id)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
Some((
|
Some((
|
||||||
|
|
|
@ -63,10 +63,10 @@ pub mod tests {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(*cmd.sku_able())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(*cmd.category_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID)
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -60,10 +60,10 @@ mod tests {
|
||||||
.name(product_name.into())
|
.name(product_name.into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(*cmd.sku_able())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(*cmd.category_id())
|
||||||
.customizations(Vec::default())
|
.customizations(Vec::default())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID)
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -10,8 +10,8 @@ use cqrs_es::{EventEnvelope, Query, View};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use super::errors::*;
|
||||||
use super::InventoryDBPostgresAdapter;
|
use super::InventoryDBPostgresAdapter;
|
||||||
use super::{errors::*, product_id_exists};
|
|
||||||
use crate::inventory::domain::events::InventoryEvent;
|
use crate::inventory::domain::events::InventoryEvent;
|
||||||
use crate::inventory::domain::product_aggregate::{
|
use crate::inventory::domain::product_aggregate::{
|
||||||
Currency, Customization, CustomizationBuilder, PriceBuilder, Product, ProductBuilder,
|
Currency, Customization, CustomizationBuilder, PriceBuilder, Product, ProductBuilder,
|
||||||
|
@ -122,27 +122,24 @@ impl From<ProductView> for Product {
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Product> for ProductView {
|
impl View<Product> for ProductView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Product>) {
|
fn update(&mut self, event: &EventEnvelope<Product>) {
|
||||||
match &event.payload {
|
if let InventoryEvent::ProductAdded(val) = &event.payload {
|
||||||
InventoryEvent::ProductAdded(val) => {
|
self.name = val.name().into();
|
||||||
self.name = val.name().into();
|
self.description = val.description().clone();
|
||||||
self.description = val.description().clone();
|
self.image = val.image().clone();
|
||||||
self.image = val.image().clone();
|
self.product_id = *val.product_id();
|
||||||
self.product_id = val.product_id().clone();
|
self.category_id = *val.category_id();
|
||||||
self.category_id = val.category_id().clone();
|
|
||||||
|
|
||||||
self.sku_able = val.sku_able().clone();
|
self.sku_able = *val.sku_able();
|
||||||
|
|
||||||
self.price_minor = val.price().minor().clone() as i32;
|
self.price_minor = *val.price().minor() as i32;
|
||||||
self.price_major = val.price().major().clone() as i32;
|
self.price_major = *val.price().major() as i32;
|
||||||
self.price_currency = val.price().currency().to_string();
|
self.price_currency = val.price().currency().to_string();
|
||||||
|
|
||||||
self.quantity_number = val.quantity().number().clone() as i32;
|
self.quantity_number = *val.quantity().number() as i32;
|
||||||
self.quantity_unit = val.quantity().unit().to_string();
|
self.quantity_unit = val.quantity().unit().to_string();
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
self.customizations = val.customizations().clone();
|
self.customizations = val.customizations().clone();
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +231,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
.await
|
.await
|
||||||
.map_err(PostgresAggregateError::from)?;
|
.map_err(PostgresAggregateError::from)?;
|
||||||
|
|
||||||
let customizations = res.get_customizations(&self).await?;
|
let customizations = res.get_customizations(self).await?;
|
||||||
Ok(Some(res.to_product_view(customizations)))
|
Ok(Some(res.to_product_view(customizations)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +270,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
.await
|
.await
|
||||||
.map_err(PostgresAggregateError::from)?;
|
.map_err(PostgresAggregateError::from)?;
|
||||||
|
|
||||||
let customizations = res.get_customizations(&self).await?;
|
let customizations = res.get_customizations(self).await?;
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
version: i64,
|
version: i64,
|
||||||
|
@ -436,7 +433,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
impl Query<Product> for InventoryDBPostgresAdapter {
|
impl Query<Product> for InventoryDBPostgresAdapter {
|
||||||
async fn dispatch(&self, product_id: &str, events: &[EventEnvelope<Product>]) {
|
async fn dispatch(&self, product_id: &str, events: &[EventEnvelope<Product>]) {
|
||||||
let res = self
|
let res = self
|
||||||
.load_with_context(&product_id)
|
.load_with_context(product_id)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
Some((
|
Some((
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub mod tests {
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
let store = StoreBuilder::default()
|
||||||
.name("store_name".into())
|
.name("store_name".into())
|
||||||
.owner(UUID.clone())
|
.owner(UUID)
|
||||||
.address(Some("store_address".into()))
|
.address(Some("store_address".into()))
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -52,7 +52,7 @@ mod tests {
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
let store = StoreBuilder::default()
|
||||||
.name("store_name".into())
|
.name("store_name".into())
|
||||||
.owner(UUID.clone())
|
.owner(UUID)
|
||||||
.address(Some("store_address".into()))
|
.address(Some("store_address".into()))
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -32,15 +32,12 @@ pub struct StoreView {
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Store> for StoreView {
|
impl View<Store> for StoreView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
fn update(&mut self, event: &EventEnvelope<Store>) {
|
||||||
match &event.payload {
|
if let InventoryEvent::StoreAdded(val) = &event.payload {
|
||||||
InventoryEvent::StoreAdded(val) => {
|
self.name = val.name().into();
|
||||||
self.name = val.name().into();
|
self.address = val.address().clone();
|
||||||
self.address = val.address().clone();
|
self.store_id = *val.store_id();
|
||||||
self.store_id = val.store_id().clone();
|
self.owner = *val.owner();
|
||||||
self.owner = val.owner().clone();
|
self.deleted = false;
|
||||||
self.deleted = false;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +184,7 @@ impl Query<Store> for SimpleLoggingQuery {
|
||||||
impl Query<Store> for InventoryDBPostgresAdapter {
|
impl Query<Store> for InventoryDBPostgresAdapter {
|
||||||
async fn dispatch(&self, store_id: &str, events: &[EventEnvelope<Store>]) {
|
async fn dispatch(&self, store_id: &str, events: &[EventEnvelope<Store>]) {
|
||||||
let res = self
|
let res = self
|
||||||
.load_with_context(&store_id)
|
.load_with_context(store_id)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| Some((StoreView::default(), ViewContext::new(store_id.into(), 0))));
|
.unwrap_or_else(|_| Some((StoreView::default(), ViewContext::new(store_id.into(), 0))));
|
||||||
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
|
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
|
||||||
|
@ -254,7 +251,7 @@ mod tests {
|
||||||
))
|
))
|
||||||
.add_category(mock_add_category_service(
|
.add_category(mock_add_category_service(
|
||||||
IS_NEVER_CALLED,
|
IS_NEVER_CALLED,
|
||||||
AddCategoryCommand::new("foo".into(), None, UUID.clone(), UUID.clone()).unwrap(),
|
AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
|
||||||
))
|
))
|
||||||
.add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
.add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
||||||
.build()
|
.build()
|
||||||
|
@ -273,7 +270,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let rand = crate::utils::random_string::GenerateRandomString {};
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID.clone()).unwrap();
|
let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID).unwrap();
|
||||||
cqrs.execute("", InventoryCommand::AddStore(cmd.clone()))
|
cqrs.execute("", InventoryCommand::AddStore(cmd.clone()))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl AddCategoryUseCase for AddCategoryService {
|
||||||
let mut category = CategoryBuilder::default()
|
let mut category = CategoryBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.store_id(cmd.store_id().clone())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id)
|
.category_id(category_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -64,7 +64,7 @@ impl AddCategoryUseCase for AddCategoryService {
|
||||||
category = CategoryBuilder::default()
|
category = CategoryBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.store_id(cmd.store_id().clone())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id)
|
.category_id(category_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -78,9 +78,9 @@ impl AddCategoryUseCase for AddCategoryService {
|
||||||
Ok(CategoryAddedEventBuilder::default()
|
Ok(CategoryAddedEventBuilder::default()
|
||||||
.name(category.name().into())
|
.name(category.name().into())
|
||||||
.description(category.description().as_ref().map(|s| s.to_string()))
|
.description(category.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(category.store_id().clone())
|
.store_id(*category.store_id())
|
||||||
.category_id(category.category_id().clone())
|
.category_id(*category.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,9 @@ pub mod tests {
|
||||||
let res = CategoryAddedEventBuilder::default()
|
let res = CategoryAddedEventBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(cmd.store_id().clone())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(UUID.clone())
|
.category_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -129,13 +129,8 @@ pub mod tests {
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
// description = None
|
||||||
let cmd = AddCategoryCommand::new(
|
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
||||||
name.into(),
|
.unwrap();
|
||||||
Some(description.into()),
|
|
||||||
store_id.clone(),
|
|
||||||
user_id.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_false(
|
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_false(
|
||||||
|
@ -162,13 +157,8 @@ pub mod tests {
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
// description = None
|
||||||
let cmd = AddCategoryCommand::new(
|
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
||||||
name.into(),
|
.unwrap();
|
||||||
Some(description.into()),
|
|
||||||
store_id.clone(),
|
|
||||||
user_id.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_true(
|
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_true(
|
||||||
|
|
|
@ -11,9 +11,7 @@ use mockall::*;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::inventory::{
|
use crate::inventory::{
|
||||||
application::port::output::db::{
|
application::port::output::db::{
|
||||||
customization_id_exists::{self, *},
|
customization_id_exists::*, customization_name_exists_for_product::*, product_id_exists::*,
|
||||||
customization_name_exists_for_product::*,
|
|
||||||
product_id_exists::*,
|
|
||||||
product_name_exists_for_category::*,
|
product_name_exists_for_category::*,
|
||||||
},
|
},
|
||||||
domain::{
|
domain::{
|
||||||
|
@ -97,9 +95,9 @@ impl AddProductUseCase for AddProductService {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(cmd.image().clone())
|
.image(cmd.image().clone())
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(*cmd.sku_able())
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(*cmd.category_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
|
@ -115,14 +113,14 @@ impl AddProductUseCase for AddProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ProductAddedEventBuilder::default()
|
Ok(ProductAddedEventBuilder::default()
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.name(product.name().into())
|
.name(product.name().into())
|
||||||
.description(product.description().as_ref().map(|s| s.to_string()))
|
.description(product.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(product.image().clone())
|
.image(product.image().clone())
|
||||||
.sku_able(product.sku_able().clone())
|
.sku_able(*product.sku_able())
|
||||||
.price(product.price().clone())
|
.price(product.price().clone())
|
||||||
.category_id(product.category_id().clone())
|
.category_id(*product.category_id())
|
||||||
.product_id(product.product_id().clone())
|
.product_id(*product.product_id())
|
||||||
.customizations(product.customizations().clone())
|
.customizations(product.customizations().clone())
|
||||||
.quantity(product.quantity().clone())
|
.quantity(product.quantity().clone())
|
||||||
.build()
|
.build()
|
||||||
|
@ -134,8 +132,6 @@ impl AddProductUseCase for AddProductService {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::inventory::domain::add_product_command::tests::get_command;
|
use crate::inventory::domain::add_product_command::tests::get_command;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
||||||
|
@ -162,13 +158,13 @@ pub mod tests {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(*cmd.sku_able())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(*cmd.category_id())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID)
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ use mockall::*;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::inventory::{
|
use crate::inventory::{
|
||||||
application::port::output::db::{
|
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
||||||
errors::InventoryDBError, store_id_exists::*, store_name_exists::*,
|
|
||||||
},
|
|
||||||
domain::{
|
domain::{
|
||||||
add_store_command::AddStoreCommand,
|
add_store_command::AddStoreCommand,
|
||||||
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
||||||
|
@ -43,8 +41,8 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
let mut store = StoreBuilder::default()
|
let mut store = StoreBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(cmd.owner().clone())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id.clone())
|
.store_id(store_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -58,8 +56,8 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
store = StoreBuilder::default()
|
store = StoreBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(cmd.owner().clone())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id.clone())
|
.store_id(store_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
continue;
|
continue;
|
||||||
|
@ -71,8 +69,8 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
Ok(StoreAddedEventBuilder::default()
|
Ok(StoreAddedEventBuilder::default()
|
||||||
.name(store.name().into())
|
.name(store.name().into())
|
||||||
.address(store.address().as_ref().map(|s| s.to_string()))
|
.address(store.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(cmd.owner().clone())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id.clone())
|
.store_id(store_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -94,8 +92,8 @@ pub mod tests {
|
||||||
let res = StoreAddedEventBuilder::default()
|
let res = StoreAddedEventBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(cmd.owner().clone())
|
.owner(*cmd.owner())
|
||||||
.store_id(UUID.clone())
|
.store_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -117,7 +115,7 @@ pub mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
|
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
|
@ -140,7 +138,7 @@ pub mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
|
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
|
|
|
@ -66,21 +66,16 @@ mod tests {
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
// description = None
|
||||||
let cmd = AddCategoryCommand::new(name.into(), None, store_id.clone(), adding_by.clone())
|
let cmd = AddCategoryCommand::new(name.into(), None, store_id, adding_by).unwrap();
|
||||||
.unwrap();
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &None);
|
assert_eq!(cmd.description(), &None);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
assert_eq!(cmd.store_id(), &store_id);
|
assert_eq!(cmd.store_id(), &store_id);
|
||||||
|
|
||||||
// description = Some
|
// description = Some
|
||||||
let cmd = AddCategoryCommand::new(
|
let cmd =
|
||||||
name.into(),
|
AddCategoryCommand::new(name.into(), Some(description.into()), store_id, adding_by)
|
||||||
Some(description.into()),
|
.unwrap();
|
||||||
store_id.clone(),
|
|
||||||
adding_by.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
|
@ -88,12 +83,7 @@ mod tests {
|
||||||
|
|
||||||
// AddCategoryCommandError::NameIsEmpty
|
// AddCategoryCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
AddCategoryCommand::new(
|
AddCategoryCommand::new("".into(), Some(description.into()), store_id, adding_by,),
|
||||||
"".into(),
|
|
||||||
Some(description.into()),
|
|
||||||
store_id.clone(),
|
|
||||||
adding_by.clone(),
|
|
||||||
),
|
|
||||||
Err(AddCategoryCommandError::NameIsEmpty)
|
Err(AddCategoryCommandError::NameIsEmpty)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,8 +181,8 @@ pub mod tests {
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.adding_by(adding_by.clone())
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
|
@ -218,8 +218,8 @@ pub mod tests {
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(None)
|
.description(None)
|
||||||
.image(None)
|
.image(None)
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.adding_by(adding_by.clone())
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
|
@ -265,9 +265,9 @@ pub mod tests {
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.adding_by(adding_by.clone())
|
.adding_by(adding_by)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.customizations(customizations.clone())
|
.customizations(customizations.clone())
|
||||||
|
@ -312,8 +312,8 @@ pub mod tests {
|
||||||
.name("".into())
|
.name("".into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.adding_by(adding_by.clone())
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
|
@ -365,8 +365,8 @@ pub mod tests {
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.adding_by(adding_by.clone())
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
|
|
|
@ -59,23 +59,23 @@ mod tests {
|
||||||
fn test_cmd() {
|
fn test_cmd() {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let address = "bar";
|
let address = "bar";
|
||||||
let owner = UUID.clone();
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), None, owner.clone()).unwrap();
|
let cmd = AddStoreCommand::new(name.into(), None, owner).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &None);
|
assert_eq!(cmd.address(), &None);
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
|
||||||
// address = Some
|
// address = Some
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
|
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
|
||||||
// AddStoreCommandError::NameIsEmpty
|
// AddStoreCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
AddStoreCommand::new("".into(), Some(address.into()), owner.clone()),
|
AddStoreCommand::new("".into(), Some(address.into()), owner),
|
||||||
Err(AddStoreCommandError::NameIsEmpty)
|
Err(AddStoreCommandError::NameIsEmpty)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,17 +55,14 @@ impl Aggregate for Category {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, event: Self::Event) {
|
fn apply(&mut self, event: Self::Event) {
|
||||||
match event {
|
if let InventoryEvent::CategoryAdded(e) = event {
|
||||||
InventoryEvent::CategoryAdded(e) => {
|
*self = CategoryBuilder::default()
|
||||||
*self = CategoryBuilder::default()
|
.name(e.name().into())
|
||||||
.name(e.name().into())
|
.category_id(*e.category_id())
|
||||||
.category_id(e.category_id().clone())
|
.description(e.description().clone())
|
||||||
.description(e.description().clone())
|
.store_id(*e.store_id())
|
||||||
.store_id(e.store_id().clone())
|
.build()
|
||||||
.build()
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,22 +93,17 @@ mod aggregate_tests {
|
||||||
let description = Some("category_description".to_string());
|
let description = Some("category_description".to_string());
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
let category_id = UUID.clone();
|
let category_id = UUID;
|
||||||
|
|
||||||
let cmd = AddCategoryCommand::new(
|
let cmd =
|
||||||
name.into(),
|
AddCategoryCommand::new(name.into(), description.clone(), store_id, adding_by).unwrap();
|
||||||
description.clone(),
|
|
||||||
store_id.clone(),
|
|
||||||
adding_by.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let expected = CategoryAddedEventBuilder::default()
|
let expected = CategoryAddedEventBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(cmd.store_id().clone())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id.clone())
|
.category_id(category_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = InventoryEvent::CategoryAdded(expected);
|
let expected = InventoryEvent::CategoryAdded(expected);
|
||||||
|
|
|
@ -53,13 +53,13 @@ pub mod tests {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(*cmd.sku_able())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(*cmd.category_id())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID)
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.customizations(customizations)
|
.customizations(customizations)
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(*cmd.adding_by())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use config::builder;
|
|
||||||
use cqrs_es::Aggregate;
|
use cqrs_es::Aggregate;
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
|
use derive_more::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -16,12 +16,17 @@ use super::{commands::InventoryCommand, events::InventoryEvent};
|
||||||
use crate::inventory::application::services::errors::*;
|
use crate::inventory::application::services::errors::*;
|
||||||
use crate::inventory::application::services::InventoryServicesInterface;
|
use crate::inventory::application::services::InventoryServicesInterface;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub enum QuantityUnit {
|
pub enum QuantityUnit {
|
||||||
|
#[display(fmt = "{}", KILO_GRAM)]
|
||||||
Kilogram,
|
Kilogram,
|
||||||
|
#[display(fmt = "{}", GRAM)]
|
||||||
Gram,
|
Gram,
|
||||||
|
#[display(fmt = "{}", DISCRETE_NUMBER)]
|
||||||
DiscreteNumber, // example: 1 sofa, 2 bed, etc.
|
DiscreteNumber, // example: 1 sofa, 2 bed, etc.
|
||||||
|
#[display(fmt = "{}", MILLI_LITER)]
|
||||||
MilliLiter,
|
MilliLiter,
|
||||||
|
#[display(fmt = "{}", LITER)]
|
||||||
Liter,
|
Liter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,19 +42,6 @@ const DISCRETE_NUMBER: &str = "discrete_number";
|
||||||
const MILLI_LITER: &str = "ml";
|
const MILLI_LITER: &str = "ml";
|
||||||
const LITER: &str = "l";
|
const LITER: &str = "l";
|
||||||
|
|
||||||
impl ToString for QuantityUnit {
|
|
||||||
fn to_string(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Kilogram => KILO_GRAM,
|
|
||||||
Self::Gram => GRAM,
|
|
||||||
Self::DiscreteNumber => DISCRETE_NUMBER,
|
|
||||||
Self::MilliLiter => MILLI_LITER,
|
|
||||||
Self::Liter => LITER,
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for QuantityUnit {
|
impl FromStr for QuantityUnit {
|
||||||
type Err = String;
|
type Err = String;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -72,22 +64,14 @@ pub struct Quantity {
|
||||||
unit: QuantityUnit,
|
unit: QuantityUnit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub enum Currency {
|
pub enum Currency {
|
||||||
|
#[display(fmt = "{}", INR)]
|
||||||
INR,
|
INR,
|
||||||
}
|
}
|
||||||
|
|
||||||
const INR: &str = "INR";
|
const INR: &str = "INR";
|
||||||
|
|
||||||
impl ToString for Currency {
|
|
||||||
fn to_string(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::INR => INR,
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Currency {
|
impl FromStr for Currency {
|
||||||
type Err = String;
|
type Err = String;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -172,23 +156,20 @@ impl Aggregate for Product {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, event: Self::Event) {
|
fn apply(&mut self, event: Self::Event) {
|
||||||
match event {
|
if let InventoryEvent::ProductAdded(e) = event {
|
||||||
InventoryEvent::ProductAdded(e) => {
|
*self = ProductBuilder::default()
|
||||||
*self = ProductBuilder::default()
|
.name(e.name().into())
|
||||||
.name(e.name().into())
|
.description(e.description().clone())
|
||||||
.description(e.description().clone())
|
.image(e.image().clone())
|
||||||
.image(e.image().clone())
|
.price(e.price().clone())
|
||||||
.price(e.price().clone())
|
.category_id(*e.category_id())
|
||||||
.category_id(e.category_id().clone())
|
.sku_able(*e.sku_able())
|
||||||
.sku_able(e.sku_able().clone())
|
.product_id(*e.product_id())
|
||||||
.product_id(e.product_id().clone())
|
.quantity(e.quantity().clone())
|
||||||
.quantity(e.quantity().clone())
|
.customizations(e.customizations().clone())
|
||||||
.customizations(e.customizations().clone())
|
.deleted(false)
|
||||||
.deleted(false)
|
.build()
|
||||||
.build()
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,15 +55,12 @@ impl Aggregate for Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply(&mut self, event: Self::Event) {
|
fn apply(&mut self, event: Self::Event) {
|
||||||
match event {
|
if let InventoryEvent::StoreAdded(e) = event {
|
||||||
InventoryEvent::StoreAdded(e) => {
|
self.name = e.name().into();
|
||||||
self.name = e.name().into();
|
self.address = e.address().as_ref().map(|s| s.to_string());
|
||||||
self.address = e.address().as_ref().map(|s| s.to_string());
|
self.owner = *e.owner();
|
||||||
self.owner = e.owner().clone();
|
self.store_id = *e.store_id();
|
||||||
self.store_id = e.store_id().clone();
|
self.deleted = false;
|
||||||
self.deleted = false;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,13 +96,13 @@ mod tests {
|
||||||
let expected = StoreAddedEventBuilder::default()
|
let expected = StoreAddedEventBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.address(address.clone())
|
.address(address.clone())
|
||||||
.store_id(store_id.clone())
|
.store_id(store_id)
|
||||||
.owner(owner.into())
|
.owner(owner)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = InventoryEvent::StoreAdded(expected);
|
let expected = InventoryEvent::StoreAdded(expected);
|
||||||
|
|
||||||
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner.clone()).unwrap();
|
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner).unwrap();
|
||||||
|
|
||||||
let mut services = MockInventoryServicesInterface::new();
|
let mut services = MockInventoryServicesInterface::new();
|
||||||
services
|
services
|
||||||
|
|
|
@ -75,8 +75,6 @@ mod tests {
|
||||||
"postgres://test_db_env_override",
|
"postgres://test_db_env_override",
|
||||||
database.url
|
database.url
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(true);
|
|
||||||
})
|
})
|
||||||
.join()
|
.join()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -65,7 +65,6 @@ mod tests {
|
||||||
"asdfasdflkjhasdlkfhalksdf",
|
"asdfasdflkjhasdlkfhalksdf",
|
||||||
server.cookie_secret
|
server.cookie_secret
|
||||||
);
|
);
|
||||||
assert!(true);
|
|
||||||
})
|
})
|
||||||
.join()
|
.join()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -10,18 +10,18 @@ pub fn parse_aggregate_id<T: Default>(
|
||||||
non_id: &str,
|
non_id: &str,
|
||||||
) -> Result<Option<(T, ViewContext)>, PersistenceError> {
|
) -> Result<Option<(T, ViewContext)>, PersistenceError> {
|
||||||
match Uuid::parse_str(aggregate_id) {
|
match Uuid::parse_str(aggregate_id) {
|
||||||
Ok(_) => return Ok(None),
|
Ok(_) => Ok(None),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if aggregate_id == non_id {
|
if aggregate_id == non_id {
|
||||||
// if store_id is unbearable, then store isn't created yet. Use cleaner, robust method
|
// if store_id is unbearable, then store isn't created yet. Use cleaner, robust method
|
||||||
// later.
|
// later.
|
||||||
return Ok(Some((
|
Ok(Some((
|
||||||
T::default(),
|
T::default(),
|
||||||
ViewContext::new(aggregate_id.into(), 0),
|
ViewContext::new(aggregate_id.into(), 0),
|
||||||
)));
|
)))
|
||||||
} else {
|
} else {
|
||||||
return Err(PersistenceError::UnknownError(Box::new(e)));
|
Err(PersistenceError::UnknownError(Box::new(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ pub mod tests {
|
||||||
let mut m = MockGetUUID::new();
|
let mut m = MockGetUUID::new();
|
||||||
|
|
||||||
if let Some(times) = times {
|
if let Some(times) = times {
|
||||||
m.expect_get_uuid().times(times).return_const(UUID.clone());
|
m.expect_get_uuid().times(times).return_const(UUID);
|
||||||
} else {
|
} else {
|
||||||
m.expect_get_uuid().return_const(UUID.clone());
|
m.expect_get_uuid().return_const(UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(m)
|
Arc::new(m)
|
||||||
|
|
Loading…
Reference in a new issue