templates_controller.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class TemplatesController < ApplicationController
  3. prepend_before_action { authentication_check && authorize! }
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some template",
  11. "user_id": null,
  12. "options":{"a":1,"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/templates.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/templates.json -v -u #{login}:#{password}
  37. =end
  38. def index
  39. model_index_render(Template, params)
  40. end
  41. =begin
  42. Resource:
  43. GET /api/v1/templates/#{id}.json
  44. Response:
  45. {
  46. "id": 1,
  47. "name": "name_1",
  48. ...
  49. }
  50. Test:
  51. curl http://localhost/api/v1/templates/#{id}.json -v -u #{login}:#{password}
  52. =end
  53. def show
  54. model_show_render(Template, params)
  55. end
  56. =begin
  57. Resource:
  58. POST /api/v1/templates.json
  59. Payload:
  60. {
  61. "name": "some name",
  62. "options":{"a":1,"b":2},
  63. }
  64. Response:
  65. {
  66. "id": 1,
  67. "name": "some_name",
  68. ...
  69. }
  70. Test:
  71. curl http://localhost/api/v1/templates.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  72. =end
  73. def create
  74. model_create_render(Template, params)
  75. end
  76. =begin
  77. Resource:
  78. PUT /api/v1/templates/{id}.json
  79. Payload:
  80. {
  81. "name": "some name",
  82. "options":{"a":1,"b":2},
  83. }
  84. Response:
  85. {
  86. "id": 1,
  87. "name": "some_name",
  88. ...
  89. }
  90. Test:
  91. curl http://localhost/api/v1/templates.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  92. =end
  93. def update
  94. model_update_render(Template, params)
  95. end
  96. =begin
  97. Resource:
  98. DELETE /api/v1/templates/{id}.json
  99. Response:
  100. {}
  101. Test:
  102. curl http://localhost/api/v1/templates.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  103. =end
  104. def destroy
  105. model_destroy_render(Template, params)
  106. end
  107. end