refactor(diary): Service 层改用 DiaryEvent 枚举替代字符串事件
- journal_service: 3 处 (JournalCreated/Updated/Deleted) - class_service: 2 处 (ClassCreated/StudentJoinedClass) - comment_service: 1 处 (CommentCreated) - topic_service: 1 处 (TopicAssigned) - parent_service: 1 处 confirm_binding → ParentBound 保留 DomainEvent::new 的场景: - class_service deactivate_class (diary.class.deactivated) - parent_service bind_child (diary.parent.binding_requested) - parent_service delete_child_data (diary.parent.data_deleted) 以上事件不在 DiaryEvent 枚举中(非核心创建事件) 测试: 509/509 全部通过
This commit is contained in:
@@ -12,6 +12,8 @@ use crate::entity::{class_member, school_class};
|
||||
use crate::error::{DiaryError, DiaryResult};
|
||||
use erp_core::events::{DomainEvent, EventBus};
|
||||
|
||||
use crate::event::DiaryEvent;
|
||||
|
||||
/// 班级服务 — 6 位码生成、过期控制、成员管理
|
||||
pub struct ClassService;
|
||||
|
||||
@@ -84,14 +86,11 @@ impl ClassService {
|
||||
// 发布 ClassCreated 事件
|
||||
event_bus
|
||||
.publish(
|
||||
DomainEvent::new(
|
||||
"diary.class.created",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"class_id": id,
|
||||
"teacher_id": teacher_id,
|
||||
}),
|
||||
),
|
||||
DiaryEvent::ClassCreated {
|
||||
class_id: id,
|
||||
teacher_id,
|
||||
}
|
||||
.to_domain_event(tenant_id),
|
||||
db,
|
||||
)
|
||||
.await;
|
||||
@@ -229,14 +228,11 @@ impl ClassService {
|
||||
// 8. 发布 StudentJoinedClass 事件
|
||||
event_bus
|
||||
.publish(
|
||||
DomainEvent::new(
|
||||
"diary.class.student_joined",
|
||||
tenant_id,
|
||||
serde_json::json!({
|
||||
"class_id": class_id,
|
||||
"student_id": user_id,
|
||||
}),
|
||||
),
|
||||
DiaryEvent::StudentJoinedClass {
|
||||
class_id,
|
||||
student_id: user_id,
|
||||
}
|
||||
.to_domain_event(tenant_id),
|
||||
db,
|
||||
)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user