use cqrs_es2::{
Aggregate,
AggregateContext,
};
pub struct PostgresSnapshotStoreAggregateContext<A>
where
A: Aggregate, {
pub aggregate_id: String,
aggregate: A,
pub current_sequence: usize,
}
impl<A> AggregateContext<A>
for PostgresSnapshotStoreAggregateContext<A>
where
A: Aggregate,
{
fn aggregate(&self) -> &A {
&self.aggregate
}
}
impl<A> PostgresSnapshotStoreAggregateContext<A>
where
A: Aggregate,
{
pub fn new(
aggregate_id: String,
aggregate: A,
current_sequence: usize,
) -> PostgresSnapshotStoreAggregateContext<A> {
PostgresSnapshotStoreAggregateContext {
aggregate_id,
aggregate,
current_sequence,
}
}
pub(crate) fn aggregate_copy(&self) -> A {
let ser = serde_json::to_value(&self.aggregate).unwrap();
serde_json::from_value(ser).unwrap()
}
}