app_permit_controller.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package controller
  2. import (
  3. "github.com/kataras/iris/v12/mvc"
  4. "xps/datamodel"
  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("GET", "/{appId:int64}/{roleId:int64}", "GetListById" )
  15. b.Handle("POST", "/add", "Create" )
  16. b.Handle("PUT", "/update", "Update" )
  17. b.Handle("DELETE", "/{appId:int64}/{roleId:int64}/{permitId:int64}", "DeleteByID" )
  18. }
  19. func (c *AppPermitController) GetList() *JsonResult {
  20. params := c.buildParams()
  21. appKey := c.GetAppKey()
  22. params["appKey"] = appKey
  23. roleId := c.Ctx.URLParamInt64Default("roleId", 0)
  24. params["roleId"] = roleId
  25. data, err := c.Service.GetList(params)
  26. if err != nil {
  27. return ResultErr(err.Error(), nil)
  28. } else {
  29. return ResultOk("获取成功", data)
  30. }
  31. }
  32. func (c *AppPermitController) GetById(appId, roleId, permitId int64) *JsonResult {
  33. data, err := c.Service.GetById(appId, roleId, permitId)
  34. if err != nil {
  35. return ResultErr(err.Error(), nil)
  36. } else {
  37. return ResultOk("获取成功", data)
  38. }
  39. }
  40. func (c *AppPermitController) GetListById(appId, roleId int64) *JsonResult {
  41. data, err := c.Service.GetListById(appId, roleId)
  42. if err != nil {
  43. return ResultErr(err.Error(), nil)
  44. } else {
  45. return ResultOk("获取成功", data)
  46. }
  47. }
  48. func (c *AppPermitController) Create() *JsonResult {
  49. userId := c.GetCurUserId()
  50. appPermit := datamodel.AppPermit{}
  51. appPermit.CreatedBy = userId
  52. if err := c.Ctx.ReadJSON(&appPermit); err != nil {
  53. return ResultErr("读取数据失败", nil)
  54. }
  55. if err := c.Service.Create(&appPermit); err != nil {
  56. return ResultErr(err.Error(), nil)
  57. } else {
  58. return ResultOk("新增成功", nil)
  59. }
  60. }
  61. func (c *AppPermitController) Update() *JsonResult {
  62. userId := c.GetCurUserId()
  63. appPermit := datamodel.AppPermit{}
  64. if err := c.Ctx.ReadJSON(&appPermit); err != nil {
  65. return ResultErr("读取数据失败", nil)
  66. }
  67. appPermit.UpdatedBy = userId
  68. if err := c.Service.Update(&appPermit); err != nil {
  69. return ResultErr(err.Error(), nil)
  70. } else {
  71. return ResultOk("更新成功", nil)
  72. }
  73. }
  74. func (c *AppPermitController) DeleteByID(appId, roleId, permitId int64) *JsonResult {
  75. userId := c.GetCurUserId()
  76. m := make(map[string]interface{})
  77. m["appId"] = appId
  78. m["roleId"] = roleId
  79. m["permitId"] = permitId
  80. m["deletedBy"] = userId
  81. if err := c.Service.Delete(m); err != nil {
  82. return ResultErr(err.Error(), nil)
  83. } else {
  84. return ResultOk("删除成功", nil)
  85. }
  86. }