From 8b8111f17e4ed3a66ff50596832032211ffdb361 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 23 Jul 2024 19:07:23 +0530 Subject: [PATCH] fix: record sale time in LineItemView --- ...18fe6888ace9e7e2b9d12f02d2c50d80e685.json} | 10 ++++- ...9ddff36d11757477e5ec130c1f4209e613dc.json} | 5 ++- ...db127ac0d070fb81e5b157a68638c3688996.json} | 5 ++- ...23095912_cqrs_ordering_line_item_query.sql | 2 +- .../adapters/output/db/line_item_view.rs | 39 +++++++++++++++++-- 5 files changed, 50 insertions(+), 11 deletions(-) rename .sqlx/{query-3f2b3da434c433067e0a68fa98ad0d7b1a00a836682d9ef20fd58c72bd5115f5.json => query-2d5ff8c368757fc2d390aaaed23d18fe6888ace9e7e2b9d12f02d2c50d80e685.json} (77%) rename .sqlx/{query-46fddc14a06f84a15fbcc04cfff9d3f41e03c73e2db7d7ee39a0f3e86cc38fe9.json => query-724e980a30694acbdc309702e5349ddff36d11757477e5ec130c1f4209e613dc.json} (77%) rename .sqlx/{query-1e7df92c508fac4c32c00621b099c673d8745b8d145b603807c771906a7af756.json => query-88f519e645dba9eb091d18e8f5c0db127ac0d070fb81e5b157a68638c3688996.json} (68%) diff --git a/.sqlx/query-3f2b3da434c433067e0a68fa98ad0d7b1a00a836682d9ef20fd58c72bd5115f5.json b/.sqlx/query-2d5ff8c368757fc2d390aaaed23d18fe6888ace9e7e2b9d12f02d2c50d80e685.json similarity index 77% rename from .sqlx/query-3f2b3da434c433067e0a68fa98ad0d7b1a00a836682d9ef20fd58c72bd5115f5.json rename to .sqlx/query-2d5ff8c368757fc2d390aaaed23d18fe6888ace9e7e2b9d12f02d2c50d80e685.json index 75532e1..e4c652e 100644 --- a/.sqlx/query-3f2b3da434c433067e0a68fa98ad0d7b1a00a836682d9ef20fd58c72bd5115f5.json +++ b/.sqlx/query-2d5ff8c368757fc2d390aaaed23d18fe6888ace9e7e2b9d12f02d2c50d80e685.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT \n product_name,\n product_id,\n line_item_id,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n deleted\n FROM\n cqrs_ordering_line_item_query\n WHERE\n line_item_id = $1;", + "query": "SELECT \n product_name,\n product_id,\n line_item_id,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n sale_time,\n deleted\n FROM\n cqrs_ordering_line_item_query\n WHERE\n line_item_id = $1;", "describe": { "columns": [ { @@ -40,6 +40,11 @@ }, { "ordinal": 7, + "name": "sale_time", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, "name": "deleted", "type_info": "Bool" } @@ -57,8 +62,9 @@ false, false, false, + false, false ] }, - "hash": "3f2b3da434c433067e0a68fa98ad0d7b1a00a836682d9ef20fd58c72bd5115f5" + "hash": "2d5ff8c368757fc2d390aaaed23d18fe6888ace9e7e2b9d12f02d2c50d80e685" } diff --git a/.sqlx/query-46fddc14a06f84a15fbcc04cfff9d3f41e03c73e2db7d7ee39a0f3e86cc38fe9.json b/.sqlx/query-724e980a30694acbdc309702e5349ddff36d11757477e5ec130c1f4209e613dc.json similarity index 77% rename from .sqlx/query-46fddc14a06f84a15fbcc04cfff9d3f41e03c73e2db7d7ee39a0f3e86cc38fe9.json rename to .sqlx/query-724e980a30694acbdc309702e5349ddff36d11757477e5ec130c1f4209e613dc.json index b89ea4b..7c919af 100644 --- a/.sqlx/query-46fddc14a06f84a15fbcc04cfff9d3f41e03c73e2db7d7ee39a0f3e86cc38fe9.json +++ b/.sqlx/query-724e980a30694acbdc309702e5349ddff36d11757477e5ec130c1f4209e613dc.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE\n cqrs_ordering_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n line_item_id = $4,\n quantity_minor_unit = $5,\n quantity_minor_number = $6,\n quantity_major_unit = $7,\n quantity_major_number = $8,\n deleted = $9;", + "query": "UPDATE\n cqrs_ordering_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n line_item_id = $4,\n quantity_minor_unit = $5,\n quantity_minor_number = $6,\n quantity_major_unit = $7,\n quantity_major_number = $8,\n sale_time = $9,\n deleted = $10;", "describe": { "columns": [], "parameters": { @@ -13,10 +13,11 @@ "Int4", "Text", "Int4", + "Timestamptz", "Bool" ] }, "nullable": [] }, - "hash": "46fddc14a06f84a15fbcc04cfff9d3f41e03c73e2db7d7ee39a0f3e86cc38fe9" + "hash": "724e980a30694acbdc309702e5349ddff36d11757477e5ec130c1f4209e613dc" } diff --git a/.sqlx/query-1e7df92c508fac4c32c00621b099c673d8745b8d145b603807c771906a7af756.json b/.sqlx/query-88f519e645dba9eb091d18e8f5c0db127ac0d070fb81e5b157a68638c3688996.json similarity index 68% rename from .sqlx/query-1e7df92c508fac4c32c00621b099c673d8745b8d145b603807c771906a7af756.json rename to .sqlx/query-88f519e645dba9eb091d18e8f5c0db127ac0d070fb81e5b157a68638c3688996.json index 18c1034..b6d3c48 100644 --- a/.sqlx/query-1e7df92c508fac4c32c00621b099c673d8745b8d145b603807c771906a7af756.json +++ b/.sqlx/query-88f519e645dba9eb091d18e8f5c0db127ac0d070fb81e5b157a68638c3688996.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO cqrs_ordering_line_item_query (\n version,\n product_name,\n product_id,\n line_item_id,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n\n deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9\n );", + "query": "INSERT INTO cqrs_ordering_line_item_query (\n version,\n product_name,\n product_id,\n line_item_id,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n sale_time,\n deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10\n );", "describe": { "columns": [], "parameters": { @@ -13,10 +13,11 @@ "Int4", "Text", "Int4", + "Timestamptz", "Bool" ] }, "nullable": [] }, - "hash": "1e7df92c508fac4c32c00621b099c673d8745b8d145b603807c771906a7af756" + "hash": "88f519e645dba9eb091d18e8f5c0db127ac0d070fb81e5b157a68638c3688996" } diff --git a/migrations/20240723095912_cqrs_ordering_line_item_query.sql b/migrations/20240723095912_cqrs_ordering_line_item_query.sql index 232c34a..6e69bbb 100644 --- a/migrations/20240723095912_cqrs_ordering_line_item_query.sql +++ b/migrations/20240723095912_cqrs_ordering_line_item_query.sql @@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS cqrs_ordering_line_item_query ( version bigint CHECK (version >= 0) NOT NULL, - sale_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP), + sale_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP) NOT NULL, line_item_id UUID NOT NULL UNIQUE, product_name TEXT NOT NULL, diff --git a/src/ordering/adapters/output/db/line_item_view.rs b/src/ordering/adapters/output/db/line_item_view.rs index bb012ad..673fc0f 100644 --- a/src/ordering/adapters/output/db/line_item_view.rs +++ b/src/ordering/adapters/output/db/line_item_view.rs @@ -8,6 +8,7 @@ use async_trait::async_trait; use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository}; use cqrs_es::{EventEnvelope, Query, View}; use serde::{Deserialize, Serialize}; +use time::OffsetDateTime; use uuid::Uuid; use super::errors::*; @@ -21,10 +22,11 @@ pub const NEW_LINE_ITEM_NON_UUID: &str = "new_line_item_non_uuid-asdfa"; // The view for a LineItem query, for a standard http application this should // be designed to reflect the response dto that will be returned to a user. -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct LineItemView { product_name: String, product_id: Uuid, + sale_time: OffsetDateTime, line_item_id: Uuid, @@ -36,6 +38,27 @@ pub struct LineItemView { deleted: bool, } + +impl Default for LineItemView { + fn default() -> Self { + Self { + sale_time: OffsetDateTime::now_utc(), + product_name: Default::default(), + product_id: Default::default(), + + line_item_id: Default::default(), + + quantity_major_number: Default::default(), + quantity_minor_number: Default::default(), + quantity_major_unit: Default::default(), + quantity_minor_unit: Default::default(), + deleted: false, + } + } +} + + + impl From for LineItem { fn from(v: LineItemView) -> Self { let quantity = QuantityBuilder::default() @@ -60,6 +83,7 @@ impl From for LineItem { .product_name(v.product_name) .line_item_id(v.line_item_id) .quantity(quantity) + .sale_time(v.sale_time) .product_id(v.product_id) .deleted(v.deleted) .build() @@ -83,6 +107,8 @@ impl View for LineItemView { self.quantity_major_unit = val.line_item().quantity().major().unit().to_string(); self.quantity_minor_unit = val.line_item().quantity().minor().unit().to_string(); + self.sale_time = val.line_item().sale_time().clone(); + self.deleted = false; } _ => (), @@ -108,6 +134,7 @@ impl ViewRepository for OrderingDBPostgresAdapter { quantity_minor_number, quantity_major_unit, quantity_major_number, + sale_time, deleted FROM cqrs_ordering_line_item_query @@ -141,6 +168,7 @@ impl ViewRepository for OrderingDBPostgresAdapter { quantity_minor_number, quantity_major_unit, quantity_major_number, + sale_time, deleted FROM cqrs_ordering_line_item_query @@ -193,10 +221,10 @@ impl ViewRepository for OrderingDBPostgresAdapter { quantity_minor_number, quantity_major_unit, quantity_major_number, - + sale_time, deleted ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9 + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 );", version, view.product_name, @@ -206,6 +234,7 @@ impl ViewRepository for OrderingDBPostgresAdapter { view.quantity_minor_number, view.quantity_major_unit, view.quantity_major_number, + view.sale_time, view.deleted, ) .execute(&self.pool) @@ -227,7 +256,8 @@ impl ViewRepository for OrderingDBPostgresAdapter { quantity_minor_number = $6, quantity_major_unit = $7, quantity_major_number = $8, - deleted = $9;", + sale_time = $9, + deleted = $10;", version, view.product_name, view.product_id, @@ -236,6 +266,7 @@ impl ViewRepository for OrderingDBPostgresAdapter { view.quantity_minor_number, view.quantity_major_unit, view.quantity_major_number, + view.sale_time, view.deleted, ) .execute(&self.pool) -- 2.39.5