remove id field in every form struct, fix cron & ddns db (#11)

This commit is contained in:
UUBulb 2024-11-19 23:34:56 +08:00 committed by GitHub
parent 3efbf9cce1
commit a1bac6e525
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 7 deletions

View File

@ -188,5 +188,6 @@ func batchDeleteCron(c *gin.Context) (any, error) {
}
singleton.OnDeleteCron(cr)
singleton.UpdateCronList()
return nil, nil
}

View File

@ -33,6 +33,15 @@ type Cron struct {
ServersRaw string `json:"-"`
}
func (c *Cron) BeforeSave(tx *gorm.DB) error {
if data, err := utils.Json.Marshal(c.Servers); err != nil {
return err
} else {
c.ServersRaw = string(data)
}
return nil
}
func (c *Cron) AfterFind(tx *gorm.DB) error {
return utils.Json.Unmarshal([]byte(c.ServersRaw), &c.Servers)
}

View File

@ -1,7 +1,6 @@
package model
type CronForm struct {
ID uint64 `json:"id,omitempty"`
TaskType uint8 `json:"task_type,omitempty" default:"0"` // 0:计划任务 1:触发任务
Name string `json:"name,omitempty" minLength:"1"`
Scheduler string `json:"scheduler,omitempty"`

View File

@ -1,8 +1,6 @@
package model
import (
"strings"
"github.com/naiba/nezha/pkg/utils"
"gorm.io/gorm"
)
@ -50,8 +48,5 @@ func (d *DDNSProfile) BeforeSave(tx *gorm.DB) error {
}
func (d *DDNSProfile) AfterFind(tx *gorm.DB) error {
if d.DomainsRaw != "" {
d.Domains = strings.Split(d.DomainsRaw, ",")
}
return nil
return utils.Json.Unmarshal([]byte(d.DomainsRaw), &d.Domains)
}