From d4bd908e91cac3397ec2f5dfa4fa398bf59211b3 Mon Sep 17 00:00:00 2001 From: zhanghan Date: Fri, 12 Sep 2025 15:41:47 +0800 Subject: [PATCH] add func for update script version --- .../script_library/controller/script_version.go | 14 ++++++++++++++ .../module/script_library/dao/script_version.go | 9 +++++++++ .../internal/module/script_library/router.go | 1 + .../script_library/service/script_version.go | 11 +++++++++++ 4 files changed, 35 insertions(+) diff --git a/automation/server/internal/module/script_library/controller/script_version.go b/automation/server/internal/module/script_library/controller/script_version.go index b7527675..3cc57520 100644 --- a/automation/server/internal/module/script_library/controller/script_version.go +++ b/automation/server/internal/module/script_library/controller/script_version.go @@ -31,3 +31,17 @@ func AddScriptVersionHandler(c *gin.Context) { } response.Success(c, nil, "success") } + +func UpdateScriptVersionHandler(c *gin.Context) { + var scriptVersion model.ScriptVersion + if err := c.ShouldBindJSON(&scriptVersion); err != nil { + response.Fail(c, nil, err.Error()) + return + } + + if err := service.UpdateScriptVersion(&scriptVersion); err != nil { + response.Fail(c, nil, err.Error()) + return + } + response.Success(c, nil, "success") +} diff --git a/automation/server/internal/module/script_library/dao/script_version.go b/automation/server/internal/module/script_library/dao/script_version.go index 4fbba1cd..1137b051 100644 --- a/automation/server/internal/module/script_library/dao/script_version.go +++ b/automation/server/internal/module/script_library/dao/script_version.go @@ -93,3 +93,12 @@ func AddScriptVersion(sv *model.ScriptVersion) error { return nil }) } + +func UpdateScriptVersion(id int, scriptId string, sv *model.ScriptVersion) error { + return global.App.MySQL.Transaction(func(tx *gorm.DB) error { + if err := tx.Model(&model.ScriptVersion{}).Where("id = ? AND script_id = ?", id, scriptId).Updates(sv).Error; err != nil { + return err + } + return nil + }) +} diff --git a/automation/server/internal/module/script_library/router.go b/automation/server/internal/module/script_library/router.go index 0a089a28..bcbb9d75 100644 --- a/automation/server/internal/module/script_library/router.go +++ b/automation/server/internal/module/script_library/router.go @@ -15,6 +15,7 @@ func ScriptLibraryHandler(router *gin.RouterGroup) { { versionGroup.GET("/list", controller.GetScriptVersionsHandler) versionGroup.POST("/add", controller.AddScriptVersionHandler) + versionGroup.PUT("/update", controller.UpdateScriptVersionHandler) } } diff --git a/automation/server/internal/module/script_library/service/script_version.go b/automation/server/internal/module/script_library/service/script_version.go index 86d6cde7..6dc7af91 100644 --- a/automation/server/internal/module/script_library/service/script_version.go +++ b/automation/server/internal/module/script_library/service/script_version.go @@ -24,3 +24,14 @@ func AddScriptVersion(sv *model.ScriptVersion) error { } return dao.AddScriptVersion(scriptVersion) } + +func UpdateScriptVersion(sv *model.ScriptVersion) error { + scriptVersion := &model.ScriptVersion{ + Content: sv.Content, + Version: sv.Version, + VersionDesc: sv.VersionDesc, + LastModifyUser: sv.LastModifyUser, + LastModifyUpdatedAt: time.Now().Format("2006-01-02 15:04:05"), + } + return dao.UpdateScriptVersion(sv.ID, sv.ScriptID, scriptVersion) +} -- Gitee