Alexander Belanger 4 лет назад
Родитель
Сommit
db92543548
2 измененных файлов с 16 добавлено и 3 удалено
  1. 3 0
      internal/repository/event.go
  2. 13 3
      internal/repository/gorm/event.go

+ 3 - 0
internal/repository/event.go

@@ -13,6 +13,9 @@ type ListEventOpts struct {
 	// can only be "timestamp" for now
 	SortBy string `schema:"sort_by"`
 
+	OwnerType string `schema:"owner_type"`
+	OwnerName string `schema:"owner_name"`
+
 	// Decrypt is whether to decrypt the underlying Data field, which may not be desired
 	// for basic list operations
 	Decrypt bool

+ 13 - 3
internal/repository/gorm/event.go

@@ -1,6 +1,7 @@
 package gorm
 
 import (
+	"fmt"
 	"strings"
 
 	"github.com/porter-dev/porter/internal/models"
@@ -77,16 +78,25 @@ func (repo *EventRepository) ListEventsByProjectID(
 
 	events := []*models.Event{}
 
+	fmt.Println("OPTS ARE", listOpts, listOpts.OwnerName, listOpts.OwnerType)
+
 	query := repo.db.Where("project_id = ? AND cluster_id = ?", projectID, opts.ClusterID)
 
 	if listOpts.Type != "" {
-		query = repo.db.Where(
-			"project_id = ? AND ref_type = ?",
-			projectID,
+		query = query.Where(
+			"ref_type = ?",
 			strings.ToLower(listOpts.Type),
 		)
 	}
 
+	if listOpts.OwnerName != "" && listOpts.OwnerType != "" {
+		query = query.Where(
+			"owner_name = ? AND owner_type = ?",
+			listOpts.OwnerName,
+			listOpts.OwnerType,
+		)
+	}
+
 	query = query.Limit(listOpts.Limit).Offset(listOpts.Skip)
 
 	if listOpts.SortBy == "timestamp" {