slas_controller.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SlasController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  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 response_full?
  40. # calendars
  41. assets = {}
  42. Calendar.all.each do |calendar|
  43. assets = calendar.assets(assets)
  44. end
  45. # slas
  46. sla_ids = []
  47. Sla.all.each do |item|
  48. sla_ids.push item.id
  49. assets = item.assets(assets)
  50. end
  51. render json: {
  52. record_ids: sla_ids,
  53. assets: assets,
  54. }, status: :ok
  55. return
  56. end
  57. model_index_render(Sla, params)
  58. end
  59. =begin
  60. Resource:
  61. GET /api/v1/slas/#{id}.json
  62. Response:
  63. {
  64. "id": 1,
  65. "name": "name_1",
  66. ...
  67. }
  68. Test:
  69. curl http://localhost/api/v1/slas/#{id}.json -v -u #{login}:#{password}
  70. =end
  71. def show
  72. model_show_render(Sla, params)
  73. end
  74. =begin
  75. Resource:
  76. POST /api/v1/slas.json
  77. Payload:
  78. {
  79. "name":"some sla",
  80. "condition":{"c_a":1,"c_b":2},
  81. "data":{"o_a":1,"o_b":2},
  82. }
  83. Response:
  84. {
  85. "id": 1,
  86. "name": "some_name",
  87. ...
  88. }
  89. Test:
  90. 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"}'
  91. =end
  92. def create
  93. model_create_render(Sla, params)
  94. end
  95. =begin
  96. Resource:
  97. PUT /api/v1/slas/{id}.json
  98. Payload:
  99. {
  100. "name":"some sla",
  101. "condition":{"c_a":1,"c_b":2},
  102. "data":{"o_a":1,"o_b":2},
  103. }
  104. Response:
  105. {
  106. "id": 1,
  107. "name": "some_name",
  108. ...
  109. }
  110. Test:
  111. 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"}'
  112. =end
  113. def update
  114. model_update_render(Sla, params)
  115. end
  116. =begin
  117. Resource:
  118. DELETE /api/v1/slas/{id}.json
  119. Response:
  120. {}
  121. Test:
  122. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  123. =end
  124. def destroy
  125. model_destroy_render(Sla, params)
  126. end
  127. end