Procházet zdrojové kódy

move NewInfraListHandler project -> infra package

Anukul Sangwan před 4 roky
rodič
revize
ec720ee24b

+ 6 - 6
api/server/handlers/project/list_infra.go → api/server/handlers/infra/list.go

@@ -1,4 +1,4 @@
-package project
+package infra
 
 import (
 	"net/http"
@@ -11,20 +11,20 @@ import (
 	"github.com/porter-dev/porter/internal/models"
 )
 
-type ProjectListInfraHandler struct {
+type InfraListHandler struct {
 	handlers.PorterHandlerWriter
 }
 
-func NewProjectListInfraHandler(
+func NewInfraListHandler(
 	config *config.Config,
 	writer shared.ResultWriter,
-) *ProjectListInfraHandler {
-	return &ProjectListInfraHandler{
+) *InfraListHandler {
+	return &InfraListHandler{
 		PorterHandlerWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
 	}
 }
 
-func (p *ProjectListInfraHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func (p *InfraListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 
 	infras, err := p.Repo().Infra().ListInfrasByProjectID(proj.ID)

+ 27 - 0
api/server/router/infra.go

@@ -52,6 +52,33 @@ func getInfraRoutes(
 
 	routes := make([]*Route, 0)
 
+	// GET /api/projects/{project_id}/infra -> project.NewInfraListHandler
+	listInfraEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbGet,
+			Method: types.HTTPVerbGet,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: "/infra",
+			},
+			Scopes: []types.PermissionScope{
+				types.UserScope,
+				types.ProjectScope,
+			},
+		},
+	)
+
+	listInfraHandler := infra.NewInfraListHandler(
+		config,
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &Route{
+		Endpoint: listInfraEndpoint,
+		Handler:  listInfraHandler,
+		Router:   r,
+	})
+
 	// GET /api/projects/{project_id}/infras/{infra_id} -> infra.NewInfraGetHandler
 	getEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{

+ 0 - 27
api/server/router/project.go

@@ -111,33 +111,6 @@ func getProjectRoutes(
 		Router:   r,
 	})
 
-	// GET /api/projects/{project_id}/infra -> project.NewListProjectInfraHandler
-	listInfraEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbGet,
-			Method: types.HTTPVerbGet,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: relPath + "/infra",
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-			},
-		},
-	)
-
-	listInfraHandler := project.NewProjectListInfraHandler(
-		config,
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &Route{
-		Endpoint: listInfraEndpoint,
-		Handler:  listInfraHandler,
-		Router:   r,
-	})
-
 	// GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
 	listClusterEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{