From 5a9117bb0bfe5e36c02131b3307f7bd8eeaccd6c Mon Sep 17 00:00:00 2001 From: vipul-rawat Date: Tue, 17 Dec 2024 12:28:05 +0530 Subject: [PATCH] change the order field to level --- application/handler/application.go | 2 +- application/handler/handler_test.go | 4 ++-- application/service/application.go | 6 +++--- application/service/application_test.go | 8 ++++---- application/service/models.go | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/application/handler/application.go b/application/handler/application.go index 53493a8..f2afb23 100644 --- a/application/handler/application.go +++ b/application/handler/application.go @@ -84,7 +84,7 @@ func (h *Handler) List(ctx *gofr.Context) (any, error) { ctx.Out.Printf(" %s \n\t", app.Name) ctx.Out.ResetColor() - sort.Slice(app.Envs, func(i, j int) bool { return app.Envs[i].Order < app.Envs[j].Order }) + sort.Slice(app.Envs, func(i, j int) bool { return app.Envs[i].Level < app.Envs[j].Level }) for _, env := range app.Envs { s.WriteString(fmt.Sprintf("%s > ", env.Name)) diff --git a/application/handler/handler_test.go b/application/handler/handler_test.go index b417817..cd29866 100644 --- a/application/handler/handler_test.go +++ b/application/handler/handler_test.go @@ -91,9 +91,9 @@ func TestHandler_List(t *testing.T) { mockSvc.EXPECT().GetApplications(gomock.Any()). Return([]svc.Application{ {ID: 1, Name: "app1", - Envs: []svc.Environment{{Name: "env1", Order: 1}, {Name: "env2", Order: 2}}}, + Envs: []svc.Environment{{Name: "env1", Level: 1}, {Name: "env2", Level: 2}}}, {ID: 2, Name: "app2", - Envs: []svc.Environment{{Name: "dev", Order: 1}, {Name: "prod", Order: 2}}}, + Envs: []svc.Environment{{Name: "dev", Level: 1}, {Name: "prod", Level: 2}}}, }, nil), }, expected: "Applications and their environments:\n\n1.\x1b[38;5;6m app1 " + diff --git a/application/service/application.go b/application/service/application.go index eb0950e..a340352 100644 --- a/application/service/application.go +++ b/application/service/application.go @@ -40,7 +40,7 @@ func (*Service) Add(ctx *gofr.Context, name string) error { app := &Application{Name: name} api := ctx.GetHTTPService("api-service") - order := 1 + level := 1 ctx.Out.Print("Do you wish to add environments to the application? (y/n) ") @@ -54,8 +54,8 @@ func (*Service) Add(ctx *gofr.Context, name string) error { ctx.Out.Print("Enter environment name: ") _, _ = fmt.Scanf("%s", &input) - envs = append(envs, Environment{Name: input, Order: order}) - order++ + envs = append(envs, Environment{Name: input, Level: level}) + level++ ctx.Out.Print("Do you wish to add more? (y/n) ") diff --git a/application/service/application_test.go b/application/service/application_test.go index 9834422..4a61ad9 100644 --- a/application/service/application_test.go +++ b/application/service/application_test.go @@ -109,8 +109,8 @@ func Test_Add_WithEnvs(t *testing.T) { name: "success with environments", userInput: "y\nprod\ny\ndev\nn\n", expectedEnvs: []Environment{ - {Name: "prod", Order: 1}, - {Name: "dev", Order: 2}, + {Name: "prod", Level: 1}, + {Name: "dev", Level: 2}, }, mockCalls: []*gomock.Call{ mocks.HTTPService.EXPECT().PostWithHeaders(ctx, "applications", nil, gomock.Any(), gomock.Any()). @@ -119,8 +119,8 @@ func Test_Add_WithEnvs(t *testing.T) { _ = json.Unmarshal(body.([]byte), &app) require.Equal(t, "test", app.Name) require.Equal(t, []Environment{ - {Name: "prod", Order: 1}, - {Name: "dev", Order: 2}, + {Name: "prod", Level: 1}, + {Name: "dev", Level: 2}, }, app.Envs) return &http.Response{StatusCode: http.StatusCreated, Body: io.NopCloser(bytes.NewBuffer(nil))}, nil }), diff --git a/application/service/models.go b/application/service/models.go index afbde97..c2080b5 100644 --- a/application/service/models.go +++ b/application/service/models.go @@ -61,8 +61,8 @@ func getAPIError(resp *http.Response) *ErrAPIService { // Environment represents an environment associated with an application. type Environment struct { Name string `json:"name"` // Name of the environment - Order int `json:"order"` // Order or priority of the environment - DeploymentSpace any `json:"deploymentSpace,omitempty"` // Optional deployment space information + Level int `json:"level"` // Priority Level of the environment + DeploymentSpace any `json:"deploymentSpace,omitempty"` // DeploymentSpace information for the environment } // Application represents an application with its associated environments.