package controllers import ( "github.com/kataras/iris/v12/mvc" "xps/datamodels" "xps/service" ) type AppCatController struct { Base Service service.AppCatService } func (c *AppCatController) BeforeActivation(b mvc.BeforeActivation) { b.Handle("GET", "/", "GetList" ) b.Handle("GET", "/page", "GetPage" ) b.Handle("GET", "/{appCatId:int64}", "GetById" ) b.Handle("POST", "/add", "Create" ) b.Handle("PUT", "/update", "Update" ) b.Handle("DELETE", "/{appCatId:int64}", "DeleteByID") } func (c *AppCatController) GetList() *JsonResult { params := c.buildParams() data, err := c.Service.GetList(params) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *AppCatController) GetPage() *JsonResult { params := c.buildParams() data, err := c.Service.GetPage(params) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *AppCatController) GetById(appCatId int64) *JsonResult { data, err := c.Service.GetById(appCatId) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *AppCatController) Create() *JsonResult { userId := c.GetCurUserId() appCat := datamodels.AppCat{} if err := c.Ctx.ReadJSON(&appCat); err != nil { return ResultErr("读取数据失败", nil) } appCat.CreatedBy = userId if err := c.Service.Create(&appCat); err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("新增成功", nil) } } func (c *AppCatController) Update() *JsonResult { userId := c.GetCurUserId() appCat := datamodels.AppCat{} if err := c.Ctx.ReadJSON(&appCat); err != nil { return ResultErr("读取数据失败", nil) } appCat.UpdatedBy = userId if err := c.Service.Update(&appCat); err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("更新成功", nil) } } func (c *AppCatController) DeleteByID(appCatId int64) *JsonResult { ocId := c.GetCurOcId() userId := c.GetCurUserId() m := make(map[string]interface{}) m["ocId"] = ocId m["appCatId"] = appCatId m["deletedBy"] = userId if err := c.Service.Delete(m); err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("删除成功", nil) } }