code refactor: set createBy when update metric_view

This commit is contained in:
Ulric Qin 2022-06-16 13:17:58 +08:00
parent 118060cf77
commit d0b005fb14
4 changed files with 14 additions and 6 deletions

View File

@ -82,7 +82,7 @@ func (v *AlertAggrView) Add() error {
return Insert(v)
}
func (v *AlertAggrView) Update(name, rule string, cate int) error {
func (v *AlertAggrView) Update(name, rule string, cate int, createBy int64) error {
if err := v.Verify(); err != nil {
return err
}
@ -92,7 +92,11 @@ func (v *AlertAggrView) Update(name, rule string, cate int) error {
v.Rule = rule
v.Cate = cate
return DB().Model(v).Select("name", "rule", "cate", "update_at").Updates(v).Error
if v.CreateBy == 0 {
v.CreateBy = createBy
}
return DB().Model(v).Select("name", "rule", "cate", "update_at", "create_by").Updates(v).Error
}
// AlertAggrViewDel: userid for safe delete

View File

@ -47,7 +47,7 @@ func (v *MetricView) Add() error {
return Insert(v)
}
func (v *MetricView) Update(name, configs string, cate int) error {
func (v *MetricView) Update(name, configs string, cate int, createBy int64) error {
if err := v.Verify(); err != nil {
return err
}
@ -57,7 +57,11 @@ func (v *MetricView) Update(name, configs string, cate int) error {
v.Configs = configs
v.Cate = cate
return DB().Model(v).Select("name", "configs", "cate", "update_at").Updates(v).Error
if v.CreateBy == 0 {
v.CreateBy = createBy
}
return DB().Model(v).Select("name", "configs", "cate", "update_at", "create_by").Updates(v).Error
}
// MetricViewDel: userid for safe delete

View File

@ -69,5 +69,5 @@ func alertAggrViewPut(c *gin.Context) {
}
}
ginx.NewRender(c).Message(view.Update(f.Name, f.Rule, f.Cate))
ginx.NewRender(c).Message(view.Update(f.Name, f.Rule, f.Cate, me.Id))
}

View File

@ -71,5 +71,5 @@ func metricViewPut(c *gin.Context) {
}
}
ginx.NewRender(c).Message(view.Update(f.Name, f.Configs, f.Cate))
ginx.NewRender(c).Message(view.Update(f.Name, f.Configs, f.Cate, me.Id))
}