Procházet zdrojové kódy

start on endpoints and models

Ivan Galakhov před 4 roky
rodič
revize
118d47b734

+ 29 - 0
internal/models/event.go

@@ -0,0 +1,29 @@
+package models
+
+import "gorm.io/gorm"
+
+type EventStatus int64
+
+const (
+	EventStatusSuccess    EventStatus = 1
+	EventStatusInProgress             = 2
+	EventStatusFailed                 = 3
+)
+
+type EventContainer struct {
+	gorm.Model
+
+	Steps []SubEvent
+}
+
+type SubEvent struct {
+	gorm.Model
+
+	EventContainerID uint
+
+	EventID string // events with the same id wil be treated the same, and the highest index one is retained
+	Name    string
+	Index   int64 // priority of the event, used for sorting
+	Status  EventStatus
+	Info    string
+}

+ 4 - 0
internal/repository/event.go

@@ -0,0 +1,4 @@
+package repository
+
+type EventRepository interface {
+}

+ 16 - 0
internal/repository/gorm/event.go

@@ -0,0 +1,16 @@
+package gorm
+
+import (
+	"github.com/porter-dev/porter/internal/repository"
+	"gorm.io/gorm"
+)
+
+type EventRepository struct {
+	db *gorm.DB
+}
+
+// NewEventRepository returns a EventRepository which uses
+// gorm.DB for querying the database
+func NewEventRepository(db *gorm.DB) repository.EventRepository {
+	return &EventRepository{db}
+}

+ 2 - 0
internal/repository/gorm/migrate.go

@@ -27,6 +27,8 @@ func AutoMigrate(db *gorm.DB) error {
 		&models.DNSRecord{},
 		&models.PWResetToken{},
 		&models.NotificationConfig{},
+		&models.SubEvent{},
+		&models.EventContainer{},
 		&ints.KubeIntegration{},
 		&ints.BasicIntegration{},
 		&ints.OIDCIntegration{},

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

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

+ 1 - 0
internal/repository/repository.go

@@ -26,4 +26,5 @@ type Repository struct {
 	GithubAppOAuthIntegration GithubAppOAuthIntegrationRepository
 	SlackIntegration          SlackIntegrationRepository
 	NotificationConfig        NotificationConfigRepository
+	Event                     EventRepository
 }

+ 19 - 0
server/api/release_handler.go

@@ -1604,6 +1604,25 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(http.StatusOK)
 }
 
+// HandleGetReleaseSteps returns a list of all steps for a given release
+// note that steps are not guaranteed to be in any specific order, so they should be ordered if needed
+func (app *App) HandleGetReleaseSteps(w http.ResponseWriter, r *http.Request) {
+
+}
+
+type HandleUpdateReleaseStepsForm struct {
+	EventID string
+	Name    string
+	Index   int64
+	Status  models.EventStatus
+	Info    string
+}
+
+// HandleUpdateReleaseSteps adds a new step to a release
+func (app *App) HandleUpdateReleaseSteps(w http.ResponseWriter, r *http.Request) {
+
+}
+
 // ------------------------ Release handler helper functions ------------------------ //
 
 // getAgentFromQueryParams uses the query params to populate a form, and then

+ 28 - 0
server/router/router.go

@@ -1235,6 +1235,34 @@ func New(a *api.App) *chi.Mux {
 				),
 			)
 
+			r.Method(
+				"GET",
+				"/projects/{project_id}/releases/{name}/steps",
+				auth.DoesUserHaveProjectAccess(
+					auth.DoesUserHaveClusterAccess(
+						requestlog.NewHandler(a.HandleGetReleaseSteps, l),
+						mw.URLParam,
+						mw.QueryParam,
+					),
+					mw.URLParam,
+					mw.ReadAccess,
+				),
+			)
+
+			r.Method(
+				"POST",
+				"/projects/{project_id}/releases/{name}/steps",
+				auth.DoesUserHaveProjectAccess(
+					auth.DoesUserHaveClusterAccess(
+						requestlog.NewHandler(a.HandleUpdateReleaseSteps, l),
+						mw.URLParam,
+						mw.QueryParam,
+					),
+					mw.URLParam,
+					mw.ReadAccess,
+				),
+			)
+
 			// /api/projects/{project_id}/gitrepos routes
 			r.Method(
 				"GET",