Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: support finding activities with multiple levels (#3895)

ZhengX84fb0face01f
diff --git a/api/activity.go b/api/activity.go
index b3164915e8..62d1c8057f 100644
--- a/api/activity.go
+++ b/api/activity.go
@@ -253,7 +253,7 @@ type ActivityFind struct {
// Domain specific fields
CreatorID *int
TypePrefixList []string
- Level *ActivityLevel
+ LevelList []ActivityLevel
ContainerID *int
Limit *int
// If specified, sorts the returned list by created_ts in <<ORDER>>
diff --git a/server/activity.go b/server/activity.go
index 15db3cc22e..1462808fb3 100644
--- a/server/activity.go
+++ b/server/activity.go
@@ -68,9 +68,12 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
if typePrefixList := c.QueryParams()["typePrefix"]; typePrefixList != nil {
activityFind.TypePrefixList = typePrefixList
}
- if levelStr := c.QueryParams().Get("level"); levelStr != "" {
- activityLevel := api.ActivityLevel(levelStr)
- activityFind.Level = &activityLevel
+ if levelList := c.QueryParams()["level"]; levelList != nil {
+ list := make([]api.ActivityLevel, len(levelList))
+ for i, level := range levelList {
+ list[i] = api.ActivityLevel(level)
+ }
+ activityFind.LevelList = list
}
if containerIDStr := c.QueryParams().Get("container"); containerIDStr != "" {
containerID, err := strconv.Atoi(containerIDStr)
diff --git a/store/activity.go b/store/activity.go
index 8c0cf6fde3..addb358897 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -344,7 +344,7 @@ func findActivityImpl(ctx context.Context, tx *Tx, find *api.ActivityFind) ([]*a
if v := find.CreatorID; v != nil {
where, args = append(where, fmt.Sprintf("creator_id = $%d", len(args)+1)), append(args, *v)
}
- if v := find.TypePrefixList; v != nil {
+ if v := find.TypePrefixList; len(v) > 0 {
var queryValues []string
// Iterate over the typePrefix list and join each one with an OR condition.
for _, str := range v {
@@ -352,8 +352,12 @@ func findActivityImpl(ctx context.Context, tx *Tx, find *api.ActivityFind) ([]*a
}
where = append(where, fmt.Sprintf("(%s)", strings.Join(queryValues, " OR ")))
}
- if v := find.Level; v != nil {
- where, args = append(where, fmt.Sprintf("level = $%d", len(args)+1)), append(args, *v)
+ if v := find.LevelList; len(v) > 0 {
+ var queryValues []string
+ for _, level := range v {
+ queryValues, args = append(queryValues, fmt.Sprintf("level = $%d", len(args)+1)), append(args, level)
+ }
+ where = append(where, fmt.Sprintf("(%s)", strings.Join(queryValues, " OR ")))
}
var query = `