Close DDD refactor and remove generated asset proxy
This commit is contained in:
@@ -116,6 +116,8 @@ fn upsert_asset_entity_binding(
|
||||
}
|
||||
};
|
||||
|
||||
emit_asset_entity_binding_changed_event(ctx, &snapshot);
|
||||
|
||||
Ok(snapshot)
|
||||
}
|
||||
|
||||
@@ -133,3 +135,37 @@ fn build_asset_entity_binding_row(snapshot: &AssetEntityBindingSnapshot) -> Asse
|
||||
updated_at: Timestamp::from_micros_since_unix_epoch(snapshot.updated_at_micros),
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_asset_entity_binding_changed_event(
|
||||
ctx: &ReducerContext,
|
||||
snapshot: &AssetEntityBindingSnapshot,
|
||||
) {
|
||||
let event = AssetEntityBindingChangedEvent {
|
||||
binding_id: snapshot.binding_id.clone(),
|
||||
asset_object_id: snapshot.asset_object_id.clone(),
|
||||
entity_kind: snapshot.entity_kind.clone(),
|
||||
entity_id: snapshot.entity_id.clone(),
|
||||
slot: snapshot.slot.clone(),
|
||||
asset_kind: snapshot.asset_kind.clone(),
|
||||
owner_user_id: snapshot.owner_user_id.clone(),
|
||||
profile_id: snapshot.profile_id.clone(),
|
||||
occurred_at_micros: snapshot.updated_at_micros,
|
||||
};
|
||||
|
||||
ctx.db.asset_event().insert(AssetEvent {
|
||||
event_id: format!(
|
||||
"assetevt_{}_{}_binding",
|
||||
event.binding_id, event.occurred_at_micros
|
||||
),
|
||||
asset_object_id: event.asset_object_id,
|
||||
binding_id: Some(event.binding_id),
|
||||
event_kind: AssetEventKind::EntityBindingChanged,
|
||||
asset_kind: event.asset_kind,
|
||||
owner_user_id: event.owner_user_id,
|
||||
profile_id: event.profile_id,
|
||||
entity_kind: Some(event.entity_kind),
|
||||
entity_id: Some(event.entity_id),
|
||||
slot: Some(event.slot),
|
||||
occurred_at: Timestamp::from_micros_since_unix_epoch(event.occurred_at_micros),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,39 @@ const ASSET_HISTORY_CHARACTER_VISUAL_KIND: &str = "character_visual";
|
||||
const ASSET_HISTORY_SCENE_IMAGE_KIND: &str = "scene_image";
|
||||
const ASSET_HISTORY_PUZZLE_COVER_IMAGE_KIND: &str = "puzzle_cover_image";
|
||||
|
||||
/// 资产事件类型。
|
||||
///
|
||||
/// 事件表只承接订阅端和审计所需的轻量事实,正式资产状态仍以
|
||||
/// `asset_object` 和 `asset_entity_binding` 为准。
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, SpacetimeType)]
|
||||
pub enum AssetEventKind {
|
||||
ObjectConfirmed,
|
||||
EntityBindingChanged,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = asset_event,
|
||||
public,
|
||||
event,
|
||||
index(accessor = by_asset_event_asset_object_id, btree(columns = [asset_object_id])),
|
||||
index(accessor = by_asset_event_owner_user_id, btree(columns = [owner_user_id])),
|
||||
index(accessor = by_asset_event_profile_id, btree(columns = [profile_id]))
|
||||
)]
|
||||
pub struct AssetEvent {
|
||||
#[primary_key]
|
||||
pub(crate) event_id: String,
|
||||
pub(crate) asset_object_id: String,
|
||||
pub(crate) binding_id: Option<String>,
|
||||
pub(crate) event_kind: AssetEventKind,
|
||||
pub(crate) asset_kind: String,
|
||||
pub(crate) owner_user_id: Option<String>,
|
||||
pub(crate) profile_id: Option<String>,
|
||||
pub(crate) entity_kind: Option<String>,
|
||||
pub(crate) entity_id: Option<String>,
|
||||
pub(crate) slot: Option<String>,
|
||||
pub(crate) occurred_at: Timestamp,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = asset_object,
|
||||
index(accessor = by_bucket_object_key, btree(columns = [bucket, object_key]))
|
||||
@@ -151,6 +184,8 @@ pub(crate) fn upsert_asset_object(
|
||||
}
|
||||
};
|
||||
|
||||
emit_asset_object_confirmed_event(ctx, &snapshot);
|
||||
|
||||
Ok(snapshot)
|
||||
}
|
||||
|
||||
@@ -232,3 +267,34 @@ fn build_asset_object_row(snapshot: &AssetObjectUpsertSnapshot) -> AssetObject {
|
||||
updated_at: Timestamp::from_micros_since_unix_epoch(snapshot.updated_at_micros),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn emit_asset_object_confirmed_event(
|
||||
ctx: &ReducerContext,
|
||||
snapshot: &AssetObjectUpsertSnapshot,
|
||||
) {
|
||||
let event = AssetObjectConfirmedEvent {
|
||||
asset_object_id: snapshot.asset_object_id.clone(),
|
||||
asset_kind: snapshot.asset_kind.clone(),
|
||||
owner_user_id: snapshot.owner_user_id.clone(),
|
||||
profile_id: snapshot.profile_id.clone(),
|
||||
entity_id: snapshot.entity_id.clone(),
|
||||
occurred_at_micros: snapshot.updated_at_micros,
|
||||
};
|
||||
|
||||
ctx.db.asset_event().insert(AssetEvent {
|
||||
event_id: format!(
|
||||
"assetevt_{}_{}_confirmed",
|
||||
event.asset_object_id, event.occurred_at_micros
|
||||
),
|
||||
asset_object_id: event.asset_object_id,
|
||||
binding_id: None,
|
||||
event_kind: AssetEventKind::ObjectConfirmed,
|
||||
asset_kind: event.asset_kind,
|
||||
owner_user_id: event.owner_user_id,
|
||||
profile_id: event.profile_id,
|
||||
entity_kind: None,
|
||||
entity_id: event.entity_id,
|
||||
slot: None,
|
||||
occurred_at: Timestamp::from_micros_since_unix_epoch(event.occurred_at_micros),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user