2025-08-27 17:33:10 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2025-09-16 15:50:22 +08:00
|
|
|
"modelRT/constants"
|
2025-08-27 17:33:10 +08:00
|
|
|
"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
|
2025-09-16 15:50:22 +08:00
|
|
|
clientToken := c.GetString("client_token")
|
|
|
|
|
if clientToken == "" {
|
|
|
|
|
err := constants.ErrGetClientToken
|
|
|
|
|
|
|
|
|
|
logger.Error(c, "failed to get client token from context", "error", err)
|
|
|
|
|
c.JSON(http.StatusOK, network.FailureResponse{
|
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
|
Msg: err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-27 17:33:10 +08:00
|
|
|
if err := c.ShouldBindJSON(&request); err != nil {
|
2025-10-14 16:12:00 +08:00
|
|
|
logger.Error(c, "failed to unmarshal attribute delete request", "error", err)
|
2025-08-27 17:33:10 +08:00
|
|
|
c.JSON(http.StatusOK, network.FailureResponse{
|
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
|
Msg: err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 15:50:22 +08:00
|
|
|
rs := diagram.NewRedisString(c, request.AttrToken, clientToken, 10, true)
|
2025-08-27 17:33:10 +08:00
|
|
|
if err := rs.GETDEL(request.AttrToken); err != nil {
|
2025-10-14 16:12:00 +08:00
|
|
|
logger.Error(c, "failed to delete attribute from Redis", "attr_token", request.AttrToken, "error", err)
|
2025-08-27 17:33:10 +08:00
|
|
|
c.JSON(http.StatusOK, network.FailureResponse{
|
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
|
Msg: err.Error(),
|
2025-11-12 17:34:18 +08:00
|
|
|
Payload: map[string]interface{}{"attr_token": request.AttrToken},
|
2025-08-27 17:33:10 +08:00
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, network.SuccessResponse{
|
|
|
|
|
Code: http.StatusOK,
|
|
|
|
|
Msg: "success",
|
2025-11-12 17:34:18 +08:00
|
|
|
Payload: map[string]interface{}{
|
2025-08-27 17:33:10 +08:00
|
|
|
"attr_token": request.AttrToken,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|