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:
@@ -113,9 +113,9 @@ func GetOpTypesBySource(source Source) []Type {
|
||||
}
|
||||
|
||||
// IsValidOpType 判断指定操作类型在给定来源下是否合法。
|
||||
func IsValidOpType(source Source, opType Type) bool {
|
||||
func IsValidOpType(source Source, opType string) bool {
|
||||
for _, t := range GetOpTypesBySource(source) {
|
||||
if t == opType {
|
||||
if string(t) == opType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ type Operation struct {
|
||||
OpID string `json:"opId" validate:"max=32"`
|
||||
Timestamp time.Time `json:"timestamp" validate:"required"`
|
||||
OpSource Source `json:"opSource" validate:"required,oneof=IRP DOIP"`
|
||||
OpType Type `json:"opType" validate:"required"`
|
||||
OpType string `json:"opType" validate:"required"`
|
||||
DoPrefix string `json:"doPrefix" validate:"required,max=512"`
|
||||
DoRepository string `json:"doRepository" validate:"required,max=512"`
|
||||
Doid string `json:"doid" validate:"required,max=512"`
|
||||
@@ -157,7 +157,7 @@ type Operation struct {
|
||||
// 自动完成哈希计算和字段校验,确保创建的 Operation 是完整且有效的。
|
||||
func NewFullOperation(
|
||||
opSource Source,
|
||||
opType Type,
|
||||
opType string,
|
||||
doPrefix, doRepository, doid string,
|
||||
producerID string,
|
||||
opActor string,
|
||||
@@ -289,7 +289,7 @@ type operationData struct {
|
||||
OpID *string `cbor:"opId"`
|
||||
Timestamp *time.Time `cbor:"timestamp"`
|
||||
OpSource *Source `cbor:"opSource"`
|
||||
OpType *Type `cbor:"opType"`
|
||||
OpType *string `cbor:"opType"`
|
||||
DoPrefix *string `cbor:"doPrefix"`
|
||||
DoRepository *string `cbor:"doRepository"`
|
||||
Doid *string `cbor:"doid"`
|
||||
|
||||
Reference in New Issue
Block a user