app_permit_controller.go 2.4 KB

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