roles_controller.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. class RolesController < ApplicationController
  2. before_filter :authentication_check
  3. =begin
  4. Format:
  5. JSON
  6. Example:
  7. {
  8. "id":1,
  9. "name":"some role",
  10. "note":"some note",
  11. "updated_at":"2012-09-14T17:51:53Z",
  12. "created_at":"2012-09-14T17:51:53Z",
  13. "updated_by_id":2,
  14. "created_by_id":2,
  15. }
  16. =end
  17. =begin
  18. Resource:
  19. GET /api/roles.json
  20. Response:
  21. [
  22. {
  23. "id": 1,
  24. "name": "some_name1",
  25. ...
  26. },
  27. {
  28. "id": 2,
  29. "name": "some_name2",
  30. ...
  31. }
  32. ]
  33. Test:
  34. curl http://localhost/api/roles.json -v -u #{login}:#{password}
  35. =end
  36. def index
  37. model_index_render(Role, params)
  38. end
  39. =begin
  40. Resource:
  41. GET /api/roles/#{id}.json
  42. Response:
  43. {
  44. "id": 1,
  45. "name": "name_1",
  46. ...
  47. }
  48. Test:
  49. curl http://localhost/api/roles/#{id}.json -v -u #{login}:#{password}
  50. =end
  51. def show
  52. model_show_render(Role, params)
  53. end
  54. =begin
  55. Resource:
  56. POST /api/roles.json
  57. Payload:
  58. {
  59. "name": "some name",
  60. "note": "",
  61. "active":true,
  62. }
  63. Response:
  64. {
  65. "id": 1,
  66. "name": "some_name",
  67. ...
  68. }
  69. Test:
  70. curl http://localhost/api/roles.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  71. =end
  72. def create
  73. return if is_not_role('Admin')
  74. model_create_render(Role, params)
  75. end
  76. =begin
  77. Resource:
  78. PUT /api/roles/{id}.json
  79. Payload:
  80. {
  81. "name": "some name",
  82. "note": "",
  83. "active":true,
  84. }
  85. Response:
  86. {
  87. "id": 1,
  88. "name": "some_name",
  89. ...
  90. }
  91. Test:
  92. curl http://localhost/api/roles.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  93. =end
  94. def update
  95. return if is_not_role('Admin')
  96. model_update_render(Role, params)
  97. end
  98. =begin
  99. Resource:
  100. Response:
  101. Test:
  102. =end
  103. def destroy
  104. return if is_not_role('Admin')
  105. model_destory_render(Role, params)
  106. end
  107. end