2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-15 20:54:28 +08:00
|
|
|
class Admin::PermalinksController < Admin::AdminController
|
2024-11-14 07:03:58 +08:00
|
|
|
before_action :fetch_permalink, only: %i[show update destroy]
|
2015-07-15 20:54:28 +08:00
|
|
|
|
|
|
|
def index
|
2015-07-17 18:23:48 +08:00
|
|
|
url = params[:filter]
|
|
|
|
permalinks = Permalink.filter_by(url)
|
2015-07-15 20:54:28 +08:00
|
|
|
render_serialized(permalinks, PermalinkSerializer)
|
|
|
|
end
|
|
|
|
|
2024-11-14 07:03:58 +08:00
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
2015-07-15 20:54:28 +08:00
|
|
|
|
2024-11-14 07:03:58 +08:00
|
|
|
def show
|
|
|
|
render_serialized(@permalink, PermalinkSerializer)
|
|
|
|
end
|
2020-05-25 17:48:54 +08:00
|
|
|
|
2024-11-14 07:03:58 +08:00
|
|
|
def create
|
2015-07-15 20:54:28 +08:00
|
|
|
permalink =
|
2024-11-14 07:03:58 +08:00
|
|
|
Permalink.create!(
|
|
|
|
url: permalink_params[:url],
|
|
|
|
permalink_type: permalink_params[:permalink_type],
|
|
|
|
permalink_type_value: permalink_params[:permalink_type_value],
|
|
|
|
)
|
|
|
|
render_serialized(permalink, PermalinkSerializer)
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
|
|
render_json_error(e.record.errors.full_messages)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@permalink.update!(
|
|
|
|
url: permalink_params[:url],
|
|
|
|
permalink_type: permalink_params[:permalink_type],
|
|
|
|
permalink_type_value: permalink_params[:permalink_type_value],
|
|
|
|
)
|
|
|
|
|
|
|
|
render_serialized(@permalink, PermalinkSerializer)
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
|
|
render_json_error(e.record.errors.full_messages)
|
2015-07-15 20:54:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@permalink.destroy
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_permalink
|
|
|
|
@permalink = Permalink.find(params[:id])
|
|
|
|
end
|
2024-11-14 07:03:58 +08:00
|
|
|
|
|
|
|
def permalink_params
|
|
|
|
params.require(:permalink).permit(:url, :permalink_type, :permalink_type_value)
|
|
|
|
end
|
2015-07-15 20:54:28 +08:00
|
|
|
end
|