overviews_controller.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class OverviewsController < ApplicationController
  3. prepend_before_action { authentication_check(permission: 'admin.overview') }
  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_ids": 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
  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 -v -u #{login}:#{password}
  42. =end
  43. def index
  44. model_index_render(Overview, params)
  45. end
  46. =begin
  47. Resource:
  48. GET /api/v1/overviews/#{id}
  49. Response:
  50. {
  51. "id": 1,
  52. "name": "name_1",
  53. ...
  54. }
  55. Test:
  56. curl http://localhost/api/v1/overviews/#{id} -v -u #{login}:#{password}
  57. =end
  58. def show
  59. model_show_render(Overview, params)
  60. end
  61. =begin
  62. Resource:
  63. POST /api/v1/overviews
  64. Payload:
  65. {
  66. "name":"some overview",
  67. "meta":{"m_a":1,"m_b":2},
  68. "condition":{"c_a":1,"c_b":2},
  69. "order":{"o_a":1,"o_b":2},
  70. "group_by":"group",
  71. "view":{"v_a":1,"v_b":2},
  72. "user_ids": null,
  73. "role_id": null,
  74. }
  75. Response:
  76. {
  77. "id": 1,
  78. "name": "some_name",
  79. ...
  80. }
  81. Test:
  82. curl http://localhost/api/v1/overviews -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  83. =end
  84. def create
  85. model_create_render(Overview, params)
  86. end
  87. =begin
  88. Resource:
  89. PUT /api/v1/overviews/{id}
  90. Payload:
  91. {
  92. "name":"some overview",
  93. "meta":{"m_a":1,"m_b":2},
  94. "condition":{"c_a":1,"c_b":2},
  95. "order":{"o_a":1,"o_b":2},
  96. "group_by":"group",
  97. "view":{"v_a":1,"v_b":2},
  98. "user_ids": null,
  99. "role_id": null,
  100. }
  101. Response:
  102. {
  103. "id": 1,
  104. "name": "some_name",
  105. ...
  106. }
  107. Test:
  108. curl http://localhost/api/v1/overviews -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  109. =end
  110. def update
  111. model_update_render(Overview, params)
  112. end
  113. =begin
  114. Resource:
  115. DELETE /api/v1/overviews/{id}
  116. Response:
  117. {}
  118. Test:
  119. curl http://localhost/api/v1/overviews/#{id} -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  120. =end
  121. def destroy
  122. model_destroy_render(Overview, params)
  123. end
  124. =begin
  125. Resource:
  126. POST /api/v1/overviews_prio
  127. Payload:
  128. {
  129. "prios": [
  130. [overview_id, prio],
  131. [overview_id, prio],
  132. [overview_id, prio],
  133. [overview_id, prio],
  134. [overview_id, prio]
  135. ]
  136. }
  137. Response:
  138. {
  139. "success": true,
  140. }
  141. Test:
  142. curl http://localhost/api/v1/overviews_prio -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"prios": [ [1,1], [44,2] ]}'
  143. =end
  144. def prio
  145. Overview.without_callback(:update, :before, :rearrangement) do
  146. params[:prios].each do |overview_prio|
  147. overview = Overview.find(overview_prio[0])
  148. next if overview.prio == overview_prio[1]
  149. overview.prio = overview_prio[1]
  150. overview.save!
  151. end
  152. end
  153. render json: { success: true }, status: :ok
  154. end
  155. end