PageRenderTime 1228ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/adamlwalker/spree
Ruby | 66 lines | 55 code | 10 blank | 1 comment | 4 complexity | 7e9d54a422e35b5e3c306811e421c5ef 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 create
  16. authorize! :create, Taxonomy
  17. @taxonomy = Taxonomy.new(taxonomy_params)
  18. if @taxonomy.save
  19. respond_with(@taxonomy, :status => 201, :default_template => :show)
  20. else
  21. invalid_resource!(@taxonomy)
  22. end
  23. end
  24. def update
  25. authorize! :update, taxonomy
  26. if taxonomy.update_attributes(taxonomy_params)
  27. respond_with(taxonomy, :status => 200, :default_template => :show)
  28. else
  29. invalid_resource!(taxonomy)
  30. end
  31. end
  32. def destroy
  33. authorize! :destroy, taxonomy
  34. taxonomy.destroy
  35. respond_with(taxonomy, :status => 204)
  36. end
  37. private
  38. def taxonomies
  39. @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
  40. ransack(params[:q]).result.
  41. page(params[:page]).per(params[:per_page])
  42. end
  43. def taxonomy
  44. @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
  45. end
  46. def taxonomy_params
  47. if params[:taxonomy] && !params[:taxonomy].empty?
  48. params.require(:taxonomy).permit(permitted_taxonomy_attributes)
  49. else
  50. {}
  51. end
  52. end
  53. end
  54. end
  55. end
  56. end