2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-15 08:54:28 -04:00
|
|
|
class Admin::PermalinksController < Admin::AdminController
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
before_action :fetch_permalink, only: [:destroy]
|
2015-07-15 08:54:28 -04:00
|
|
|
|
|
|
|
def index
|
2015-07-17 06:23:48 -04:00
|
|
|
url = params[:filter]
|
|
|
|
permalinks = Permalink.filter_by(url)
|
2015-07-15 08:54:28 -04:00
|
|
|
render_serialized(permalinks, PermalinkSerializer)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
params.require(:url)
|
|
|
|
params.require(:permalink_type)
|
|
|
|
params.require(:permalink_type_value)
|
|
|
|
|
|
|
|
permalink = Permalink.new(:url => params[:url], params[:permalink_type] => params[:permalink_type_value])
|
|
|
|
if permalink.save
|
|
|
|
render_serialized(permalink, PermalinkSerializer)
|
|
|
|
else
|
|
|
|
render_json_error(permalink)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@permalink.destroy
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_permalink
|
|
|
|
@permalink = Permalink.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|