Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/handler/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions application/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down
6 changes: 3 additions & 3 deletions application/service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) ")

Expand All @@ -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) ")

Expand Down
8 changes: 4 additions & 4 deletions application/service/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()).
Expand All @@ -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
}),
Expand Down
4 changes: 2 additions & 2 deletions application/service/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading