feat: add BadgeRefresher interface and badge types
This commit is contained in:
parent
1ede7d50be
commit
2c89ce4d42
42
badges/badges.go
Normal file
42
badges/badges.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package badges
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
// BadgeRule defines a condition for automatic badge assignment.
|
||||||
|
type BadgeRule struct {
|
||||||
|
Field string `json:"field"`
|
||||||
|
Operator string `json:"operator"` // eq, neq, gt, gte, lt, lte, contains, exists, true, false
|
||||||
|
Value any `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BadgeDefinition defines a badge with auto-computation rules.
|
||||||
|
type BadgeDefinition struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Rules []BadgeRule `json:"rules"`
|
||||||
|
RulesMode string `json:"rules_mode"` // "and" or "or"
|
||||||
|
ManualOnly bool `json:"manual_only"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseDefinitions extracts badge definitions from a data table schema JSON.
|
||||||
|
func ParseDefinitions(schemaJSON []byte) []BadgeDefinition {
|
||||||
|
var schema map[string]any
|
||||||
|
if err := json.Unmarshal(schemaJSON, &schema); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
badgesRaw, ok := schema["badges"]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(badgesRaw)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var definitions []BadgeDefinition
|
||||||
|
if err := json.Unmarshal(raw, &definitions); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return definitions
|
||||||
|
}
|
||||||
@ -49,6 +49,7 @@ type ServiceDeps struct {
|
|||||||
// Core RPC services — pre-built bindings for CMS-provided services
|
// Core RPC services — pre-built bindings for CMS-provided services
|
||||||
CoreServiceBindings CoreServiceBindings
|
CoreServiceBindings CoreServiceBindings
|
||||||
ReviewSubmitter ReviewSubmitter
|
ReviewSubmitter ReviewSubmitter
|
||||||
|
BadgeRefresher BadgeRefresher
|
||||||
|
|
||||||
// Extension points — typed as narrow interfaces where possible
|
// Extension points — typed as narrow interfaces where possible
|
||||||
JobRunner JobRunner
|
JobRunner JobRunner
|
||||||
@ -85,3 +86,10 @@ type RAGResult struct {
|
|||||||
Score float64
|
Score float64
|
||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BadgeRefresher recomputes badges for a data table row.
|
||||||
|
// The CMS handles loading the table schema, aggregating ratings,
|
||||||
|
// evaluating badge rules, and persisting the updated badge list.
|
||||||
|
type BadgeRefresher interface {
|
||||||
|
RefreshBadges(ctx context.Context, tableID, rowID uuid.UUID) error
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user