You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
3.0 KiB
52 lines
3.0 KiB
package util
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
"product/backend/handlers/base"
|
|
"product/backend/models"
|
|
"product/backend/moo/db"
|
|
"product/backend/moo/log"
|
|
)
|
|
|
|
// ChangeImageUrl
|
|
func ChangeImageUrl(ctx *gin.Context) {
|
|
// bind request data
|
|
req := ChangeImageUrlReq{}
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
log.Error(err)
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": base.Translate(err),
|
|
})
|
|
return
|
|
}
|
|
|
|
errs := map[string]error{}
|
|
|
|
errs["Competition"] = db.DB.Model(&models.Competition{}).Where("1 = 1").Unscoped().Update("logo", gorm.Expr("REPLACE(`logo`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Directive"] = db.DB.Model(&models.Directive{}).Where("1 = 1").Unscoped().Update("logo", gorm.Expr("REPLACE(`logo`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["DirectiveGroup"] = db.DB.Model(&models.DirectiveGroup{}).Where("1 = 1").Unscoped().Update("image", gorm.Expr("REPLACE(`image`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["KnowledgeGroup"] = db.DB.Model(&models.KnowledgeGroup{}).Where("1 = 1").Unscoped().Update("logo", gorm.Expr("REPLACE(`logo`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Lesson"] = db.DB.Model(&models.Lesson{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["LessonGroup"] = db.DB.Model(&models.LessonGroup{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["LessonStep"] = db.DB.Model(&models.LessonStep{}).Where("1 = 1").Unscoped().Update("image_addr", gorm.Expr("REPLACE(`image_addr`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["LessonType"] = db.DB.Model(&models.LessonType{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Paper"] = db.DB.Model(&models.Paper{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Product"] = db.DB.Model(&models.Product{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Product"] = db.DB.Model(&models.Product{}).Where("1 = 1").Unscoped().Updates(map[string]any{
|
|
"cover": gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost),
|
|
"code_basic": gorm.Expr("REPLACE(`code_basic`, ?, ?)", req.OldHost, req.NewHost),
|
|
"code_reference": gorm.Expr("REPLACE(`code_reference`, ?, ?)", req.OldHost, req.NewHost),
|
|
}).Error
|
|
errs["ProductGroup"] = db.DB.Model(&models.ProductGroup{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Question"] = db.DB.Model(&models.Question{}).Where("1 = 1").Unscoped().Update("cover", gorm.Expr("REPLACE(`cover`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
errs["Subject"] = db.DB.Model(&models.Subject{}).Where("1 = 1").Unscoped().Update("logo", gorm.Expr("REPLACE(`logo`, ?, ?)", req.OldHost, req.NewHost)).Error
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"data": errs,
|
|
})
|
|
}
|