postgres_es2/aggregates/
postgres_snapshot_store_aggregate_context.rs1use cqrs_es2::{
2 Aggregate,
3 AggregateContext,
4};
5
6pub struct PostgresSnapshotStoreAggregateContext<A>
8where
9 A: Aggregate, {
10 pub aggregate_id: String,
13 aggregate: A,
15 pub current_sequence: usize,
18}
19
20impl<A> AggregateContext<A>
21 for PostgresSnapshotStoreAggregateContext<A>
22where
23 A: Aggregate,
24{
25 fn aggregate(&self) -> &A {
26 &self.aggregate
27 }
28}
29
30impl<A> PostgresSnapshotStoreAggregateContext<A>
31where
32 A: Aggregate,
33{
34 pub fn new(
36 aggregate_id: String,
37 aggregate: A,
38 current_sequence: usize,
39 ) -> PostgresSnapshotStoreAggregateContext<A> {
40 PostgresSnapshotStoreAggregateContext {
41 aggregate_id,
42 aggregate,
43 current_sequence,
44 }
45 }
46
47 pub(crate) fn aggregate_copy(&self) -> A {
48 let ser = serde_json::to_value(&self.aggregate).unwrap();
49 serde_json::from_value(ser).unwrap()
50 }
51}