slas_controller.rb 2.5 KB

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