/
destroy.go
54 lines (48 loc) · 1.24 KB
/
destroy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nodes
import (
"net/http"
orm "github.com/coolray-dev/raydash/database"
"github.com/coolray-dev/raydash/models"
"github.com/coolray-dev/raydash/modules/log"
"github.com/gin-gonic/gin"
)
type destroyResponse struct {
Node string `json:"node"`
}
// Destroy receive a id from request and delete in from DB
//
// Destroy godoc
// @Summary Destroy Node
// @Description Destroy Node according to nid
// @ID Nodes.Destroy
// @Security ApiKeyAuth
// @Tags Nodes
// @Accept json
// @Produce json
// @Param nid path uint true "Node ID"
// @Param Authorization header string true "Access Token"
// @Success 200 {object} destroyResponse
// @Failure 403 {object} handler.ErrorResponse
// @Failure 500 {object} handler.ErrorResponse
// @Router /nodes/{nid} [delete]
func Destroy(c *gin.Context) {
nid, err := parseNID(c)
if err != nil {
log.Log.WithError(err).Warn("Error Getting Node ID")
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var node models.Node
node.ID = nid
if err = orm.DB.Delete(&node).Error; err != nil {
log.Log.WithError(err).Error("Database Error")
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
c.JSON(http.StatusOK, destroyResponse{
Node: "",
})
return
}