2016-09-24 11:00:46 +08:00
|
|
|
# frozen_string_literal: true
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2013-02-28 20:16:04 -05:00
|
|
|
class MappingsController < ApplicationController
|
2017-11-25 11:23:47 -08:00
|
|
|
before_action :require_user, only: %i(create update destroy)
|
2016-03-11 22:10:31 +08:00
|
|
|
after_action :verify_authorized, except: :index
|
|
|
|
after_action :verify_policy_scoped, only: :index
|
2016-07-26 08:14:23 +08:00
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
respond_to :json
|
2016-07-26 08:14:23 +08:00
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# GET /mappings/1.json
|
|
|
|
def show
|
|
|
|
@mapping = Mapping.find(params[:id])
|
2016-03-12 11:16:46 +11:00
|
|
|
authorize @mapping
|
2013-02-28 19:56:27 -05:00
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
render json: @mapping
|
2013-02-28 19:56:27 -05:00
|
|
|
end
|
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# POST /mappings.json
|
2013-02-28 19:56:27 -05:00
|
|
|
def create
|
2015-09-19 20:01:44 +08:00
|
|
|
@mapping = Mapping.new(mapping_params)
|
2016-03-12 11:16:46 +11:00
|
|
|
authorize @mapping
|
|
|
|
@mapping.user = current_user
|
2016-12-16 16:51:52 -05:00
|
|
|
@mapping.updated_by = current_user
|
2013-02-28 20:56:57 -05:00
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
if @mapping.save
|
|
|
|
render json: @mapping, status: :created
|
|
|
|
else
|
|
|
|
render json: @mapping.errors, status: :unprocessable_entity
|
2013-02-28 19:56:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# PUT /mappings/1.json
|
2013-02-28 19:56:27 -05:00
|
|
|
def update
|
2014-07-27 15:57:35 -04:00
|
|
|
@mapping = Mapping.find(params[:id])
|
2016-03-12 11:16:46 +11:00
|
|
|
authorize @mapping
|
2016-12-16 16:51:52 -05:00
|
|
|
@mapping.updated_by = current_user
|
2017-02-09 16:53:19 -05:00
|
|
|
@mapping.map.updated_by = current_user
|
2016-12-16 16:51:52 -05:00
|
|
|
@mapping.assign_attributes(mapping_params)
|
2014-07-27 15:57:35 -04:00
|
|
|
|
2016-12-16 16:51:52 -05:00
|
|
|
if @mapping.save
|
2014-07-27 15:57:35 -04:00
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: @mapping.errors, status: :unprocessable_entity
|
|
|
|
end
|
2013-02-28 19:56:27 -05:00
|
|
|
end
|
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# DELETE /mappings/1.json
|
2013-02-28 19:56:27 -05:00
|
|
|
def destroy
|
2014-07-27 15:57:35 -04:00
|
|
|
@mapping = Mapping.find(params[:id])
|
2016-03-12 11:16:46 +11:00
|
|
|
authorize @mapping
|
2016-12-16 16:51:52 -05:00
|
|
|
@mapping.updated_by = current_user
|
2017-02-09 16:53:19 -05:00
|
|
|
@mapping.map.updated_by = current_user
|
2014-07-27 15:57:35 -04:00
|
|
|
@mapping.destroy
|
|
|
|
|
2016-07-26 08:14:23 +08:00
|
|
|
head :no_content
|
2013-02-28 19:56:27 -05:00
|
|
|
end
|
2015-09-19 16:26:34 +08:00
|
|
|
|
|
|
|
private
|
2016-07-26 08:14:23 +08:00
|
|
|
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
|
|
def mapping_params
|
|
|
|
params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id)
|
|
|
|
end
|
2014-10-07 19:11:55 -04:00
|
|
|
end
|