package handler import ( "net/http" "modelRT/database" "modelRT/logger" "modelRT/network" "github.com/gin-gonic/gin" ) // MeasurementGetHandler retrieves the value of measurement data func MeasurementGetHandler(c *gin.Context) { var request network.MeasurementGetRequest if err := c.ShouldBindJSON(&request); err != nil { logger.Error(c, "Failed to unmarshal measurement get request", "error", err) c.JSON(http.StatusOK, network.FailureResponse{ Code: http.StatusBadRequest, Msg: err.Error(), }) return } // TODO 增加 redis 数据读取步骤 pgClient := database.GetPostgresDBClient() tx := pgClient.Begin() attrModel, err := database.ParseAttrToken(c, tx, request.MeasurementToken) if err != nil { tx.Rollback() logger.Error(c, "Failed to parse attribute token", "attr_token", request.MeasurementToken, "error", err) c.JSON(http.StatusOK, network.FailureResponse{ Code: http.StatusBadRequest, Msg: err.Error(), PayLoad: map[string]interface{}{"attr_token": request.MeasurementToken}, }) return } tx.Commit() // The GetAttrValue method is assumed to exist on the AttrModelInterface. // You need to add this method to your attribute_model.go interface definition. attrValue := attrModel.GetAttrValue() c.JSON(http.StatusOK, network.SuccessResponse{ Code: http.StatusOK, Msg: "success", PayLoad: map[string]interface{}{ "attr_token": request.MeasurementToken, "attr_value": attrValue, }, }) }