package controller import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "project_management/app/e" "project_management/app/model" "project_management/app/services" "project_management/unity" ) var Capabilities services.Capabilities = &model.Capabilities{} // GetCapabilities 获取所有能力 func GetCapabilities(c *gin.Context) { var params unity.CapQueryPageParams var capabilities model.Capabilities if err := c.ShouldBindJSON(¶ms); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } queryCond := "cap_name like ?" params.Query = "%" + params.Query + "%" result, total, err := Capabilities.GetCapabilitiesList(params, capabilities, queryCond) if err != nil { e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg()) return } else { e.CapResPonsePage(c, result, total, params) return } } // AdminGetCapabilities 管理员获取所有功能列表 func AdminGetCapabilities(c *gin.Context) { var params unity.QueryPageParams var capabilities model.Capabilities if err := c.ShouldBindJSON(¶ms); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } queryCond := "cap_name like ?" params.Query = "%" + params.Query + "%" result, total, err := Capabilities.AdminGetCapabilitiesList(params, capabilities, queryCond) if err != nil { e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg()) return } e.ResPonsePage(c, result, total, params) return } // AdminAddGetCapabilities 添加能力 func AdminAddGetCapabilities(c *gin.Context) { var capabilities model.Capabilities if err := c.ShouldBindJSON(&capabilities); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } id := unity.RandomIds(4) for model.CapIdISRepeat(id) { id = unity.RandomIds(4) } capabilities.CapId = id addCapabilities := Capabilities.AddCapabilities(capabilities) if addCapabilities == e.SUCCESS { e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg()) return } e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg()) } // AdminUpdateCapabilities 更新能力 func AdminUpdateCapabilities(c *gin.Context) { var capabilities model.Capabilities if err := c.ShouldBindJSON(&capabilities); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(capabilities); err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } updateCapabilities := Capabilities.UpdateCapabilities(capabilities) if updateCapabilities == e.SUCCESS { e.ResponseSuccess(c, nil) return } e.ResponseWithMsg(c, updateCapabilities, updateCapabilities.GetMsg()) } // AdminDeleteCap 删除功能 func AdminDeleteCap(c *gin.Context) { var capabilities model.Capabilities if err := c.ShouldBindJSON(&capabilities); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } capre := Capabilities.DeleteCapabilities(capabilities.CapId) if capre == e.SUCCESS { e.ResponseSuccess(c, nil) return } e.ResponseWithMsg(c, capre, capre.GetMsg()) }