fix: return code and message to FE issue

This commit is contained in:
2024-09-09 17:19:50 +08:00
parent 9a14520da6
commit c4533da0e0
3 changed files with 7 additions and 7 deletions

View File

@@ -295,7 +295,7 @@ func (k *KpiCReport) Put(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
if err := dborm.DefaultDB().First(&report, id).Error; err != nil { if err := dborm.DefaultDB().First(&report, id).Error; err != nil {
c.JSON(http.StatusOK, services.ErrResp("KPI report not found")) c.JSON(http.StatusOK, services.ErrResp("custom indicator report not found"))
return return
} }
@@ -311,7 +311,7 @@ func (k *KpiCReport) Delete(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
if err := dborm.DefaultDB().Delete(&KpiCReport{}, id).Error; err != nil { if err := dborm.DefaultDB().Delete(&KpiCReport{}, id).Error; err != nil {
c.JSON(http.StatusOK, services.ErrResp("KPI report not found")) c.JSON(http.StatusOK, services.ErrResp("custom indicator report not found"))
return return
} }

View File

@@ -128,7 +128,7 @@ func (k *KpiCTitle) Post(c *gin.Context) {
} }
result := dborm.DefaultDB().Where("ne_type=? and (kpi_id=? or title=?)", title.NeType, title.KpiID, title.Title).First(&title) result := dborm.DefaultDB().Where("ne_type=? and (kpi_id=? or title=?)", title.NeType, title.KpiID, title.Title).First(&title)
if result.RowsAffected > 0 { if result.RowsAffected > 0 {
c.JSON(http.StatusOK, services.ErrResp("target kpiC title already exist")) c.JSON(http.StatusOK, services.ErrResp("custom indicator already exist"))
return return
} }
if err := dborm.DefaultDB().Create(&title).Error; err != nil { if err := dborm.DefaultDB().Create(&title).Error; err != nil {
@@ -162,7 +162,7 @@ func (k *KpiCTitle) Put(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
if err := dborm.DefaultDB().First(&title, id).Error; err != nil { if err := dborm.DefaultDB().First(&title, id).Error; err != nil {
c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found")) c.JSON(http.StatusOK, services.ErrResp("custom indicator not found"))
return return
} }
@@ -179,7 +179,7 @@ func (k *KpiCTitle) Delete(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil { if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil {
c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found")) c.JSON(http.StatusOK, services.ErrResp("custom indicator not found"))
return return
} }

View File

@@ -6,7 +6,7 @@ const (
) )
func ErrResp(msg string) map[string]any { func ErrResp(msg string) map[string]any {
return map[string]any{"code": CODE_FAIL, "message": msg} return map[string]any{"code": CODE_FAIL, "msg": msg}
} }
func DataResp(data any) map[string]any { func DataResp(data any) map[string]any {
@@ -14,7 +14,7 @@ func DataResp(data any) map[string]any {
} }
func SuccMessageResp() map[string]any { func SuccMessageResp() map[string]any {
return map[string]any{"code": CODE_SUCC, "message": "success"} return map[string]any{"code": CODE_SUCC, "msg": "success"}
} }
func TotalResp(total int64) map[string]any { func TotalResp(total int64) map[string]any {