Merge pull request 'fix: record sale time in LineItemView' (#65) from line-item-sale-time into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Reviewed-on: #65
This commit is contained in:
Aravinth Manivannan 2024-07-23 19:16:41 +05:30
commit a1a8b47878
5 changed files with 50 additions and 11 deletions

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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,

View file

@ -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<LineItemView> for LineItem {
fn from(v: LineItemView) -> Self {
let quantity = QuantityBuilder::default()
@ -60,6 +83,7 @@ impl From<LineItemView> 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<LineItem> 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<LineItemView, LineItem> 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<LineItemView, LineItem> 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<LineItemView, LineItem> 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<LineItemView, LineItem> 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<LineItemView, LineItem> 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<LineItemView, LineItem> for OrderingDBPostgresAdapter {
view.quantity_minor_number,
view.quantity_major_unit,
view.quantity_major_number,
view.sale_time,
view.deleted,
)
.execute(&self.pool)