app_permit_controller.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package controllers
  2. import (
  3. "github.com/kataras/iris/v12/mvc"
  4. "xps/datamodels"
  5. "xps/service"
  6. )
  7. type AppPermitController struct {
  8. Base
  9. Service service.AppPermitService
  10. }
  11. func (c *AppPermitController) BeforeActivation(b mvc.BeforeActivation) {
  12. b.Handle("GET", "", "GetList" )
  13. b.Handle("GET", "/{appId:int64}/{roleId:int64}/{permitId:int64}", "GetById" )
  14. b.Handle("POST", "/add", "Create" )
  15. b.Handle("PUT", "/update", "Update" )
  16. b.Handle("DELETE", "/{appId:int64}/{roleId:int64}/{permitId:int64}", "DeleteByID")
  17. }
  18. func (c *AppPermitController) GetList() *JsonResult {
  19. params := c.buildParams()
  20. appId := c.Ctx.URLParamInt64Default("appId", 0)
  21. params["appId"] = appId
  22. roleId := c.Ctx.URLParamInt64Default("roleId", 0)
  23. params["roleId"] = roleId
  24. data, err := c.Service.GetList(params)
  25. if err != nil {
  26. return ResultErr(err.Error(), nil)
  27. } else {
  28. return ResultOk("获取成功", data)
  29. }
  30. }
  31. func (c *AppPermitController) GetById(appId, roleId, permitId int64) *JsonResult {
  32. data, err := c.Service.GetById(appId, roleId, permitId)
  33. if err != nil {
  34. return ResultErr(err.Error(), nil)
  35. } else {
  36. return ResultOk("获取成功", data)
  37. }
  38. }
  39. func (c *AppPermitController) Create() *JsonResult {
  40. userId := c.GetCurUserId()
  41. appPermit := datamodels.AppPermit{}
  42. appPermit.CreatedBy = userId
  43. if err := c.Ctx.ReadJSON(&appPermit); err != nil {
  44. return ResultErr("读取数据失败", nil)
  45. }
  46. if err := c.Service.Create(&appPermit); err != nil {
  47. return ResultErr(err.Error(), nil)
  48. } else {
  49. return ResultOk("新增成功", nil)
  50. }
  51. }
  52. func (c *AppPermitController) Update() *JsonResult {
  53. userId := c.GetCurUserId()
  54. appPermit := datamodels.AppPermit{}
  55. if err := c.Ctx.ReadJSON(&appPermit); err != nil {
  56. return ResultErr("读取数据失败", nil)
  57. }
  58. appPermit.UpdatedBy = userId
  59. if err := c.Service.Update(&appPermit); err != nil {
  60. return ResultErr(err.Error(), nil)
  61. } else {
  62. return ResultOk("更新成功", nil)
  63. }
  64. }
  65. func (c *AppPermitController) DeleteByID(appId, roleId, permitId int64) *JsonResult {
  66. userId := c.GetCurUserId()
  67. m := make(map[string]interface{})
  68. m["appId"] = appId
  69. m["roleId"] = roleId
  70. m["permitId"] = permitId
  71. m["deletedBy"] = userId
  72. if err := c.Service.Delete(m); err != nil {
  73. return ResultErr(err.Error(), nil)
  74. } else {
  75. return ResultOk("删除成功", nil)
  76. }
  77. }