overviews_controller.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class OverviewsController < ApplicationController
  3. before_filter :authentication_check
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some overview",
  11. "meta":{"m_a":1,"m_b":2},
  12. "condition":{"c_a":1,"c_b":2},
  13. "order":{"o_a":1,"o_b":2},
  14. "group_by":"group",
  15. "view":{"v_a":1,"v_b":2},
  16. "user_id": null,
  17. "role_id": null,
  18. "updated_at":"2012-09-14T17:51:53Z",
  19. "created_at":"2012-09-14T17:51:53Z",
  20. "updated_by_id":2.
  21. "created_by_id":2,
  22. }
  23. =end
  24. =begin
  25. Resource:
  26. GET /api/v1/overviews.json
  27. Response:
  28. [
  29. {
  30. "id": 1,
  31. "name": "some_name1",
  32. ...
  33. },
  34. {
  35. "id": 2,
  36. "name": "some_name2",
  37. ...
  38. }
  39. ]
  40. Test:
  41. curl http://localhost/api/v1/overviews.json -v -u #{login}:#{password}
  42. =end
  43. def index
  44. return if deny_if_not_role('Admin')
  45. model_index_render(Overview, params)
  46. end
  47. =begin
  48. Resource:
  49. GET /api/v1/overviews/#{id}.json
  50. Response:
  51. {
  52. "id": 1,
  53. "name": "name_1",
  54. ...
  55. }
  56. Test:
  57. curl http://localhost/api/v1/overviews/#{id}.json -v -u #{login}:#{password}
  58. =end
  59. def show
  60. return if deny_if_not_role('Admin')
  61. model_show_render(Overview, params)
  62. end
  63. =begin
  64. Resource:
  65. POST /api/v1/overviews.json
  66. Payload:
  67. {
  68. "name":"some overview",
  69. "meta":{"m_a":1,"m_b":2},
  70. "condition":{"c_a":1,"c_b":2},
  71. "order":{"o_a":1,"o_b":2},
  72. "group_by":"group",
  73. "view":{"v_a":1,"v_b":2},
  74. "user_id": null,
  75. "role_id": null,
  76. }
  77. Response:
  78. {
  79. "id": 1,
  80. "name": "some_name",
  81. ...
  82. }
  83. Test:
  84. curl http://localhost/api/v1/overviews.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  85. =end
  86. def create
  87. return if deny_if_not_role('Admin')
  88. model_create_render(Overview, params)
  89. end
  90. =begin
  91. Resource:
  92. PUT /api/v1/overviews/{id}.json
  93. Payload:
  94. {
  95. "name":"some overview",
  96. "meta":{"m_a":1,"m_b":2},
  97. "condition":{"c_a":1,"c_b":2},
  98. "order":{"o_a":1,"o_b":2},
  99. "group_by":"group",
  100. "view":{"v_a":1,"v_b":2},
  101. "user_id": null,
  102. "role_id": null,
  103. }
  104. Response:
  105. {
  106. "id": 1,
  107. "name": "some_name",
  108. ...
  109. }
  110. Test:
  111. curl http://localhost/api/v1/overviews.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  112. =end
  113. def update
  114. return if deny_if_not_role('Admin')
  115. model_update_render(Overview, params)
  116. end
  117. =begin
  118. Resource:
  119. DELETE /api/v1/overviews/{id}.json
  120. Response:
  121. {}
  122. Test:
  123. curl http://localhost/api/v1/overviews.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  124. =end
  125. def destroy
  126. return if deny_if_not_role('Admin')
  127. model_destory_render(Overview, params)
  128. end
  129. end