PageRenderTime 1788ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/api/app/controllers/spree/api/v1/taxonomies_controller.rb

https://gitlab.com/shinvdu/spree
Ruby | 69 lines | 57 code | 11 blank | 1 comment | 4 complexity | 4e468e7b6287adc7fc13f25bbb38b62b MD5 | raw file
  1. module Spree
  2. module Api
  3. module V1
  4. class TaxonomiesController < Spree::Api::BaseController
  5. def index
  6. respond_with(taxonomies)
  7. end
  8. def show
  9. respond_with(taxonomy)
  10. end
  11. # Because JSTree wants parameters in a *slightly* different format
  12. def jstree
  13. show
  14. end
  15. def new
  16. end
  17. def create
  18. authorize! :create, Taxonomy
  19. @taxonomy = Taxonomy.new(taxonomy_params)
  20. if @taxonomy.save
  21. respond_with(@taxonomy, status: 201, default_template: :show)
  22. else
  23. invalid_resource!(@taxonomy)
  24. end
  25. end
  26. def update
  27. authorize! :update, taxonomy
  28. if taxonomy.update_attributes(taxonomy_params)
  29. respond_with(taxonomy, status: 200, default_template: :show)
  30. else
  31. invalid_resource!(taxonomy)
  32. end
  33. end
  34. def destroy
  35. authorize! :destroy, taxonomy
  36. taxonomy.destroy
  37. respond_with(taxonomy, status: 204)
  38. end
  39. private
  40. def taxonomies
  41. @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(root: :children).
  42. ransack(params[:q]).result.
  43. page(params[:page]).per(params[:per_page])
  44. end
  45. def taxonomy
  46. @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
  47. end
  48. def taxonomy_params
  49. if params[:taxonomy] && !params[:taxonomy].empty?
  50. params.require(:taxonomy).permit(permitted_taxonomy_attributes)
  51. else
  52. {}
  53. end
  54. end
  55. end
  56. end
  57. end
  58. end