diff --git a/features/pm/kpi_c_report/controller.go b/features/pm/kpi_c_report/controller.go index 60bd8c72..14e8981e 100644 --- a/features/pm/kpi_c_report/controller.go +++ b/features/pm/kpi_c_report/controller.go @@ -70,7 +70,7 @@ func (k *KpiCReport) Get(c *gin.Context) { //err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error err := dbg.Find(&reports).Error if err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } c.JSON(http.StatusOK, services.DataResp(reports)) @@ -83,7 +83,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) { var querys KpiCReportQuery if err := c.ShouldBindQuery(&querys); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -92,7 +92,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) { conditions = append(conditions, "ne_type = ?") params = append(params, strings.ToUpper(querys.NeType)) } else { - c.JSON(http.StatusBadRequest, services.ErrResp("Not found required parameter NE type")) + c.JSON(http.StatusOK, services.ErrResp("Not found required parameter NE type")) return } tableName := TableName() + "_" + strings.ToLower(querys.NeType) @@ -136,7 +136,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) { //err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error err := dbg.Find(&results).Error if err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -169,7 +169,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) { var querys KpiCReportQuery if err := c.ShouldBindQuery(&querys); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -178,7 +178,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) { conditions = append(conditions, "ne_type = ?") params = append(params, strings.ToUpper(querys.NeType)) } else { - c.JSON(http.StatusBadRequest, services.ErrResp("Not found NE type")) + c.JSON(http.StatusOK, services.ErrResp("Not found NE type")) return } tableName := TableName() + "_" + strings.ToLower(querys.NeType) @@ -203,7 +203,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) { var total int64 = 0 err := dbg.Count(&total).Error if err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -224,7 +224,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) { //err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error err = dbg.Find(&reports).Error if err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -237,7 +237,7 @@ func (k *KpiCReport) Total(c *gin.Context) { var querys KpiCReportQuery if err := c.ShouldBindQuery(&querys); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -246,7 +246,7 @@ func (k *KpiCReport) Total(c *gin.Context) { conditions = append(conditions, "ne_type = ?") params = append(params, strings.ToUpper(querys.NeType)) } else { - c.JSON(http.StatusBadRequest, services.ErrResp("Not found NE type")) + c.JSON(http.StatusOK, services.ErrResp("Not found NE type")) return } tableName := TableName() + "_" + strings.ToLower(querys.NeType) @@ -269,7 +269,7 @@ func (k *KpiCReport) Total(c *gin.Context) { var total int64 = 0 err := dbg.Count(&total).Error if err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -280,11 +280,11 @@ func (k *KpiCReport) Post(c *gin.Context) { var report KpiCReport if err := c.ShouldBindJSON(&report); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } if err := dborm.DefaultDB().Create(&report).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } c.JSON(http.StatusCreated, services.DataResp(report)) @@ -295,12 +295,12 @@ func (k *KpiCReport) Put(c *gin.Context) { id := c.Param("id") if err := dborm.DefaultDB().First(&report, id).Error; err != nil { - c.JSON(http.StatusNotFound, services.ErrResp("KPI report not found")) + c.JSON(http.StatusOK, services.ErrResp("KPI report not found")) return } if err := c.ShouldBindJSON(&report); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } dborm.DefaultDB().Save(&report) @@ -311,7 +311,7 @@ func (k *KpiCReport) Delete(c *gin.Context) { id := c.Param("id") if err := dborm.DefaultDB().Delete(&KpiCReport{}, id).Error; err != nil { - c.JSON(http.StatusNotFound, services.ErrResp("KPI report not found")) + c.JSON(http.StatusOK, services.ErrResp("KPI report not found")) return } diff --git a/features/pm/kpi_c_title/controller.go b/features/pm/kpi_c_title/controller.go index 68d3e5c7..48a0b993 100644 --- a/features/pm/kpi_c_title/controller.go +++ b/features/pm/kpi_c_title/controller.go @@ -17,7 +17,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) { var querys KpiCTitleQuery if err := c.ShouldBindQuery(&querys); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -40,7 +40,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) { // Get total number var total int64 = 0 if err := dbg.Count(&total).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -58,7 +58,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) { dbg = dbg.Order(orderBy) } if err := dbg.Find(&titles).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -85,7 +85,7 @@ func (k *KpiCTitle) Get(c *gin.Context) { whereSql += strings.Join(conditions, " and ") } if err := dborm.DefaultDB().Where(whereSql, params...).Find(&titles).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -112,7 +112,7 @@ func (k *KpiCTitle) Total(c *gin.Context) { } var total int64 = 0 if err := dborm.DefaultDB().Table(k.TableName()).Where(whereSql, params...).Count(&total).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } @@ -123,16 +123,16 @@ func (k *KpiCTitle) Post(c *gin.Context) { var title KpiCTitle if err := c.ShouldBindJSON(&title); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } result := dborm.DefaultDB().Where("ne_type=? and (kpi_id=? or title=?)", title.NeType, title.KpiID, title.Title).First(&title) if result.RowsAffected > 0 { - c.JSON(http.StatusInternalServerError, services.ErrResp("target kpiC title already exist")) + c.JSON(http.StatusOK, services.ErrResp("target kpiC title already exist")) return } if err := dborm.DefaultDB().Create(&title).Error; err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } kpiCReportTable := "kpi_c_report_" + strings.ToLower(*title.NeType) @@ -140,17 +140,17 @@ func (k *KpiCTitle) Post(c *gin.Context) { // clone table "kpi_c_report" to "kpi_c_report_{neType}" sql := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s AS SELECT * FROM %s WHERE 1=0", kpiCReportTable, "kpi_c_report") if _, err := dborm.ExecSQL(sql, nil); err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } sql = fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN `id` int(11) NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY IF NOT EXISTS (`id`)", kpiCReportTable) if _, err := dborm.ExecSQL(sql, nil); err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } sql = fmt.Sprintf("ALTER TABLE %s ADD INDEX IF NOT EXISTS `idx_timestamp`(`created_at`) USING BTREE, ADD INDEX IF NOT EXISTS `idx_uid_datetime`(`rm_uid`, `date`, `start_time`) USING BTREE", kpiCReportTable) if _, err := dborm.ExecSQL(sql, nil); err != nil { - c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } } @@ -162,12 +162,12 @@ func (k *KpiCTitle) Put(c *gin.Context) { id := c.Param("id") if err := dborm.DefaultDB().First(&title, id).Error; err != nil { - c.JSON(http.StatusNotFound, services.ErrResp("KPIC Title not found")) + c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found")) return } if err := c.ShouldBindJSON(&title); err != nil { - c.JSON(http.StatusBadRequest, services.ErrResp(err.Error())) + c.JSON(http.StatusOK, services.ErrResp(err.Error())) return } dborm.DefaultDB().Save(&title) @@ -179,7 +179,7 @@ func (k *KpiCTitle) Delete(c *gin.Context) { id := c.Param("id") if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil { - c.JSON(http.StatusNotFound, services.ErrResp("KPIC Title not found")) + c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found")) return }