فهرست منبع

finish update notification endpoint

Ivan Galakhov 4 سال پیش
والد
کامیت
aad502d047

+ 2 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/NotificationSettingsSection.tsx

@@ -38,8 +38,9 @@ const NotificationSettingsSection: React.FC<Props> = (props) => {
       .updateNotificationConfig(
         "<token>",
         {
-          payload: JSON.stringify(payload),
           namespace: props.currentChart.namespace,
+          cluster_id: currentCluster.id,
+          payload,
         },
         {
           project_id: currentProject.id,

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -272,6 +272,7 @@ const updateNotificationConfig = baseApi<
   {
     payload: any;
     namespace: string;
+    cluster_id: string;
   },
   {
     project_id: number;

+ 1 - 0
internal/repository/gorm/repository.go

@@ -32,5 +32,6 @@ func NewRepository(db *gorm.DB, key *[32]byte) *repository.Repository {
 		GithubAppInstallation:     NewGithubAppInstallationRepository(db),
 		GithubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(db),
 		SlackIntegration:          NewSlackIntegrationRepository(db, key),
+		NotificationConfig:        NewNotificationConfigRepository(db),
 	}
 }

+ 1 - 0
internal/repository/repository.go

@@ -25,4 +25,5 @@ type Repository struct {
 	GithubAppInstallation     GithubAppInstallationRepository
 	GithubAppOAuthIntegration GithubAppOAuthIntegrationRepository
 	SlackIntegration          SlackIntegrationRepository
+	NotificationConfig        NotificationConfigRepository
 }

+ 32 - 2
server/api/notifications_handler.go

@@ -2,8 +2,8 @@ package api
 
 import (
 	"encoding/json"
-	"fmt"
 	"github.com/go-chi/chi"
+	"github.com/porter-dev/porter/internal/models"
 	"net/http"
 )
 
@@ -38,5 +38,35 @@ func (app *App) HandleUpdateNotificationConfig(w http.ResponseWriter, r *http.Re
 		}, w)
 	}
 
-	fmt.Println(release)
+	// either create a new notification config or update the current one
+	newConfig := &models.NotificationConfig{
+		Enabled: form.Payload.Enabled,
+		Deploy:  form.Payload.Deploy,
+		Success: form.Payload.Success,
+		Failure: form.Payload.Failure,
+	}
+
+	if release.NotificationConfig == 0 {
+		newConfig, err = app.Repo.NotificationConfig.CreateNotificationConfig(newConfig)
+
+		if err != nil {
+			app.handleErrorInternal(err, w)
+			return
+		}
+
+		release.NotificationConfig = newConfig.ID
+
+		release, err = app.Repo.Release.UpdateRelease(release)
+
+	} else {
+		newConfig.ID = release.NotificationConfig
+		newConfig, err = app.Repo.NotificationConfig.UpdateNotificationConfig(newConfig)
+	}
+
+	if err != nil {
+		app.handleErrorInternal(err, w)
+		return
+	}
+
+	w.WriteHeader(http.StatusOK)
 }