package adm_controller import ( "Blog/internal/consts" "Blog/internal/model" "Blog/internal/model/result" "Blog/internal/repository" "Blog/internal/service" "Blog/internal/utils" "time" "github.com/google/uuid" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/sessions" ) type VersionController struct { Ctx iris.Context Session *sessions.Session } func (c *VersionController) Get() { c.Ctx.View("/admin/version/index.html") } func (ctrl *VersionController) GetList() { var versions []model.SysVersion repository.VersionRepository.Table(consts.TABLE_SYS_VERSION).Order("create_time Desc").Find(&versions) service.VersionService.FindVersions() ctrl.Ctx.JSON(result.Ok(versions)) } func (ctrl *VersionController) PostSubmit() { var version model.SysVersion if err := ctrl.Ctx.ReadBody(&version); err != nil { ctrl.Ctx.JSON(result.Error("读取版本参数失败")) return } user := utils.SessionUtil.GetUser(ctrl.Session) now := time.Now().UnixMilli() version.Id = uuid.NewString() version.CreateBy = user.Id version.CreateTime = now version.State = "1" version.Del = 0 err := repository.VersionRepository.Table(consts.TABLE_SYS_VERSION).Create(&version).Error if err != nil { ctrl.Ctx.JSON(result.Error("添加版本信息失败")) } ctrl.Ctx.JSON(result.Ok(version)) }