refactor: 将 OpType 字段从枚举类型改为 string 类型

主要变更:
- Operation.OpType: Type → string
- NewFullOperation 参数: opType Type → opType string
- IsValidOpType 参数: opType Type → opType string
- operationMeta.OpType: *Type → *string
- queryclient.ListRequest.OpType: model.Type → string

优点:
- 更灵活,支持动态扩展操作类型
- 不再受限于预定义的枚举常量
- 简化类型转换逻辑

兼容性:
- Type 常量定义保持不变 (OpTypeCreate, OpTypeUpdate 等)
- 使用时需要 string() 转换: string(model.OpTypeCreate)
- 所有单元测试已更新并通过 (100%)

测试结果:
 api/adapter - PASS
 api/highclient - PASS
 api/logger - PASS
 api/model - PASS
 api/persistence - PASS
 api/queryclient - PASS
 internal/* - PASS
This commit is contained in:
ryan
2025-12-24 16:48:00 +08:00
parent 4b72a37120
commit a90d853a6e
16 changed files with 52 additions and 52 deletions

View File

@@ -54,7 +54,7 @@ func TestFromProtobuf_Basic(t *testing.T) {
assert.Equal(t, "op-123", result.OpID)
assert.Equal(t, now.Unix(), result.Timestamp.Unix())
assert.Equal(t, model.Source("IRP"), result.OpSource)
assert.Equal(t, model.Type("OC_CREATE_HANDLE"), result.OpType)
assert.Equal(t, "OC_CREATE_HANDLE", result.OpType)
assert.Equal(t, "test", result.DoPrefix)
assert.Equal(t, "repo", result.DoRepository)
assert.Equal(t, "test/repo/123", result.Doid)
@@ -133,7 +133,7 @@ func TestToProtobuf_Basic(t *testing.T) {
OpID: "op-123",
Timestamp: now,
OpSource: model.OpSourceIRP,
OpType: model.OpTypeOCCreateHandle,
OpType: string(model.OpTypeOCCreateHandle),
DoPrefix: "test",
DoRepository: "repo",
Doid: "test/repo/123",
@@ -166,7 +166,7 @@ func TestToProtobuf_WithHashes(t *testing.T) {
OpID: "op-123",
Timestamp: now,
OpSource: model.OpSourceDOIP,
OpType: model.OpTypeCreate,
OpType: string(model.OpTypeCreate),
DoPrefix: "test",
DoRepository: "repo",
Doid: "test/repo/123",
@@ -192,7 +192,7 @@ func TestToProtobuf_WithoutHashes(t *testing.T) {
OpID: "op-123",
Timestamp: now,
OpSource: model.OpSourceDOIP,
OpType: model.OpTypeCreate,
OpType: string(model.OpTypeCreate),
DoPrefix: "test",
DoRepository: "repo",
Doid: "test/repo/123",
@@ -511,7 +511,7 @@ func TestRoundTrip_Operation(t *testing.T) {
OpID: "op-123",
Timestamp: now,
OpSource: model.OpSourceIRP,
OpType: model.OpTypeOCCreateHandle,
OpType: string(model.OpTypeOCCreateHandle),
DoPrefix: "test",
DoRepository: "repo",
Doid: "test/repo/123",