Răsfoiți Sursa

页面管理

huangyan 5 luni în urmă
părinte
comite
1918e94a71

+ 30 - 0
app/controller/pageManage.go

@@ -43,6 +43,36 @@ func GetPageManage(c *gin.Context) {
 	e.ResPonsePage(c, result, total, page)
 }
 
+// GetPageManageById 获取页面详情
+func GetPageManageById(c *gin.Context) {
+	uid := unity.GetUId(c)
+	s := c.Query("id")
+	validate := validator.New()
+	err := validate.Var(s, "required,numeric")
+	if err != nil {
+		e.ResponseWithMsg(c, e.ERROR, "id不能为空")
+		return
+	}
+	id, _ := strconv.Atoi(s)
+	if uid == 0 {
+		e.ResponseWithMsg(c, e.TheUserIsEmpty, e.TheUserIsEmpty.GetMsg())
+		return
+	} else if uid == 1 {
+		result, err := unity.GetById(id, model.PageManage{})
+		if err != nil {
+			e.ResponseWithMsg(c, e.ERROR, err.Error())
+			return
+		}
+		e.ResponseSuccess(c, result)
+	}
+	byId, err := PageManage.GetPageManageById(uid, id)
+	if err != nil {
+		e.ResponseWithMsg(c, e.ERROR, err.Error())
+		return
+	}
+	e.ResponseSuccess(c, byId)
+}
+
 // AddPageManage 添加页面管理
 func AddPageManage(c *gin.Context) {
 	var page model.PageManage

+ 9 - 0
app/model/pageManage.go

@@ -15,6 +15,15 @@ type PageManage struct {
 	Data    string `gorm:"type:longtext;comment:页面数据" json:"data" validate:"required"`
 }
 
+func (p PageManage) GetPageManageById(uid, id int) (PageManage, error) {
+	//TODO implement me
+	tx := global.DBLink.Where("id=?", id).Where("user_id=?", uid).First(&p)
+	if tx.RowsAffected > 0 {
+		return p, nil
+	}
+	return PageManage{}, errors.New("没有找到该页面")
+}
+
 func (p PageManage) GetPageManage(params unity.QueryPageParams, model PageManage, queryCond interface{}) (result []PageManage, total int64, err error) {
 	//TODO implement me
 	var count int64

+ 1 - 0
app/routers/pageManage.go

@@ -11,4 +11,5 @@ func PageManageRouter(r *gin.Engine) {
 	group.POST("/addpageManage", controller.AddPageManage)
 	group.PUT("/pageManage", controller.UpdatePageManage)
 	group.DELETE("/pageManage", controller.DeletePageManage)
+	group.GET("/pageManage", controller.GetPageManageById)
 }

+ 1 - 0
app/service/pageManage.go

@@ -9,4 +9,5 @@ type Page interface {
 	DeletePageManageById(uid, id int) error
 	UpdatePageManage(manage model.PageManage) error
 	GetPageManage(params unity.QueryPageParams, model model.PageManage, queryCond interface{}) (result []model.PageManage, total int64, err error)
+	GetPageManageById(uid, id int) (model.PageManage, error)
 }