44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"modelRT/diagram"
|
||
|
|
"modelRT/logger"
|
||
|
|
"modelRT/network"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AttrDeleteHandler deletes a data attribute
|
||
|
|
func AttrDeleteHandler(c *gin.Context) {
|
||
|
|
var request network.AttrDeleteRequest
|
||
|
|
if err := c.ShouldBindJSON(&request); err != nil {
|
||
|
|
logger.Error(c, "Failed to unmarshal attribute delete request", "error", err)
|
||
|
|
c.JSON(http.StatusOK, network.FailureResponse{
|
||
|
|
Code: http.StatusBadRequest,
|
||
|
|
Msg: err.Error(),
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
rs := diagram.NewRedisString(c, request.AttrToken, "", 10, true)
|
||
|
|
if err := rs.GETDEL(request.AttrToken); err != nil {
|
||
|
|
logger.Error(c, "Failed to delete attribute from Redis", "attr_token", request.AttrToken, "error", err)
|
||
|
|
c.JSON(http.StatusOK, network.FailureResponse{
|
||
|
|
Code: http.StatusBadRequest,
|
||
|
|
Msg: err.Error(),
|
||
|
|
PayLoad: map[string]interface{}{"attr_token": request.AttrToken},
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
c.JSON(http.StatusOK, network.SuccessResponse{
|
||
|
|
Code: http.StatusOK,
|
||
|
|
Msg: "success",
|
||
|
|
PayLoad: map[string]interface{}{
|
||
|
|
"attr_token": request.AttrToken,
|
||
|
|
},
|
||
|
|
})
|
||
|
|
}
|