# frozen_string_literal: true

module Admin
  class PlaceCategorizationsController < Admin::BaseAdminController
    before_action :pundit_authorization

    def create
      @place_cat = PlaceCategorization.new(place_categorization_params)

      if @place_cat.save
        redirect_to categories_admin_place_path(@place_cat.place)
      else
        redirect_to categories_admin_place_path(@place_cat.place), alert: 'Could not create Place Category.'
      end
    end

    def destroy
      @place_cat = PlaceCategorization.find(params[:id])
      @place_cat.destroy
      redirect_back(fallback_location: categories_admin_place_path(@place_cat.place))
    end

    private

    def place_categorization_params
      params.require(:place_categorization).permit(:place_id, :category_id)
    end

    def pundit_authorization
      authorize :place_categorization
    end
  end
end
