Skip to content
Open
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 rest-api/api/pkg/api/handler/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,5 +1504,5 @@ func (dah DeleteAllocationHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package handler

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/NVIDIA/infra-controller/rest-api/api/pkg/api/model"
)

func assertDeletionAcceptedResponse(t *testing.T, body []byte) {
t.Helper()

var resp model.APIDeletionAcceptedResponse
require.NoError(t, json.Unmarshal(body, &resp))
assert.Equal(t, model.DeletionRequestAcceptedMessage, resp.Message)
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/infinibandpartition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,6 @@ func (dibph DeleteInfiniBandPartitionHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())

}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4954,7 +4954,7 @@ func (dih DeleteInstanceHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}

// GetInstanceStatusDetailsHandler is the API Handler for getting Instance StatusDetail records
Expand Down
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9707,7 +9707,7 @@ func TestDeleteInstanceHandler_Handle(t *testing.T) {
if tt.args.respCode != http.StatusAccepted {
return
}
assert.Contains(t, rec.Body.String(), "Deletion request was accepted")
assertDeletionAcceptedResponse(t, rec.Body.Bytes())

// Verify Instance in terminating state
insDAO := cdbm.NewInstanceDAO(dbSession)
Expand Down
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,5 +1551,5 @@ func (dith DeleteInstanceTypeHandler) Handle(c echo.Context) error {
// Create response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/ipblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,5 +1167,5 @@ func (dipbh DeleteIPBlockHandler) Handle(c echo.Context) error {
// Create response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1957,5 +1957,5 @@ func (umh DeleteMachineHandler) Handle(c echo.Context) error {

logger.Info().Msg("finishing API handler")

return c.JSON(http.StatusAccepted, nil)
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/machineinstancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,5 +752,5 @@ func (dmith DeleteMachineInstanceTypeHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/machinevalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,5 +1671,5 @@ func (handler DeleteMachineValidationExternalConfigHandler) Handle(c echo.Contex

// Create response
logger.Info().Msg("finishing API handler")
return c.JSON(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/networksecuritygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ func (dnsgh DeleteNetworkSecurityGroupHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}

// ~~~~~ Delete Handler ~~~~~ //
Expand Down
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/nvlinklogicalpartition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,5 +1352,5 @@ func (dibph DeleteNVLinkLogicalPartitionHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/operatingsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,6 @@ func (dsh DeleteOperatingSystemHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())

}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ func (dsh DeleteSiteHandler) Handle(c echo.Context) error {
// Create response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}

// GetSiteStatusDetailsHandler is the API Handler for getting Site StatusDetail records
Expand Down
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,5 +1008,5 @@ func (dskh DeleteSSHKeyHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/sshkeygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,5 +1659,5 @@ func (dskgh DeleteSSHKeyGroupHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,5 +1164,5 @@ func (dsh DeleteSubnetHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/tenantaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,5 +866,5 @@ func (dtah DeleteTenantAccountHandler) Handle(c echo.Context) error {
// Create response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,5 +1818,5 @@ func (dvh DeleteVPCHandler) Handle(c echo.Context) error {
// Return response
logger.Info().Msg("finishing API handler")

return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ func TestDeleteVPCHandler_Handle(t *testing.T) {
if tt.args.respCode != http.StatusAccepted {
return
}
assert.Contains(t, rec.Body.String(), "Deletion request was accepted")
assertDeletionAcceptedResponse(t, rec.Body.Bytes())

// Verify VPC in deleting state
vpcDAO := cdbm.NewVpcDAO(dbSession)
Expand Down
2 changes: 1 addition & 1 deletion rest-api/api/pkg/api/handler/vpcprefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,5 +1160,5 @@ func (dsh DeleteVpcPrefixHandler) Handle(c echo.Context) error {

// Create response
logger.Info().Msg("finishing API handler")
return c.String(http.StatusAccepted, "Deletion request was accepted")
return c.JSON(http.StatusAccepted, model.NewAPIDeletionAcceptedResponse())
}
22 changes: 22 additions & 0 deletions rest-api/api/pkg/api/model/deletion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining this inside the model, should we use the ‘/handler/util’ path? Since this pertains to API messages and all related routes or queries, we defined it in the util module. However, this is just my suggestion.


const (
// DeletionRequestAcceptedMessage is returned when an asynchronous delete has
// been accepted for processing.
DeletionRequestAcceptedMessage = "Deletion request was accepted"
)

// APIDeletionAcceptedResponse is the JSON body for accepted async DELETE requests.
type APIDeletionAcceptedResponse struct {
Message string `json:"message"`
}

// NewAPIDeletionAcceptedResponse returns the JSON body for accepted async deletes.
func NewAPIDeletionAcceptedResponse() APIDeletionAcceptedResponse {
return APIDeletionAcceptedResponse{
Message: DeletionRequestAcceptedMessage,
}
}
24 changes: 24 additions & 0 deletions rest-api/api/pkg/api/model/deletion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package model

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAPIDeletionAcceptedResponse_JSON(t *testing.T) {
t.Parallel()

payload, err := json.Marshal(NewAPIDeletionAcceptedResponse())
require.NoError(t, err)
assert.JSONEq(t, `{"message":"`+DeletionRequestAcceptedMessage+`"}`, string(payload))

var decoded APIDeletionAcceptedResponse
require.NoError(t, json.Unmarshal(payload, &decoded))
assert.Equal(t, DeletionRequestAcceptedMessage, decoded.Message)
}
Loading
Loading