2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-15 07:54:28 -05:00
|
|
|
class Admin::PermalinksController < Admin::AdminController
|
2017-08-30 23:06:56 -05:00
|
|
|
before_action :fetch_permalink, only: [:destroy]
|
2015-07-15 07:54:28 -05:00
|
|
|
|
|
|
|
def index
|
2015-07-17 05:23:48 -05:00
|
|
|
url = params[:filter]
|
|
|
|
permalinks = Permalink.filter_by(url)
|
2015-07-15 07:54:28 -05:00
|
|
|
render_serialized(permalinks, PermalinkSerializer)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
params.require(:url)
|
|
|
|
params.require(:permalink_type)
|
|
|
|
params.require(:permalink_type_value)
|
|
|
|
|
2020-05-25 04:48:54 -05:00
|
|
|
if params[:permalink_type] == "tag_name"
|
|
|
|
params[:permalink_type] = "tag_id"
|
|
|
|
params[:permalink_type_value] = Tag.find_by_name(params[:permalink_type_value])&.id
|
|
|
|
end
|
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
permalink =
|
|
|
|
Permalink.new(:url => params[:url], params[:permalink_type] => params[:permalink_type_value])
|
2015-07-15 07:54:28 -05:00
|
|
|
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
|