checklist_templates_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ChecklistTemplatesController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def index
  5. model_index_render(ChecklistTemplate, params)
  6. end
  7. def show
  8. model_show_render(ChecklistTemplate, params)
  9. end
  10. def create
  11. checklist_template = ChecklistTemplate.create!(checklist_template_params)
  12. checklist_template.replace_items!(checklist_template_items_params) if checklist_template_items_params.present?
  13. render json: checklist_template.attributes_with_association_ids, status: :created
  14. end
  15. def update
  16. checklist_template = ChecklistTemplate.find(params[:id])
  17. checklist_template.update!(checklist_template_params)
  18. checklist_template.replace_items!(checklist_template_items_params) if checklist_template_items_params.present?
  19. render json: checklist_template.attributes_with_association_ids, status: :ok
  20. end
  21. def destroy
  22. model_destroy_render(ChecklistTemplate, params)
  23. end
  24. private
  25. def checklist_template_params
  26. params.permit(:name, :active)
  27. end
  28. def checklist_template_items_params
  29. @checklist_template_items_params ||= params[:items]
  30. .presence
  31. &.compact_blank
  32. end
  33. end