2013-03-01 01:16:04 +00:00
|
|
|
class MappingsController < ApplicationController
|
2014-07-27 19:57:35 +00:00
|
|
|
|
|
|
|
before_filter :require_user, only: [:create, :update, :destroy]
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
# GET /mappings/1.json
|
|
|
|
def show
|
|
|
|
@mapping = Mapping.find(params[:id])
|
2013-03-01 00:56:27 +00:00
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
render json: @mapping
|
2013-03-01 00:56:27 +00:00
|
|
|
end
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# POST /mappings.json
|
2013-03-01 00:56:27 +00:00
|
|
|
def create
|
2015-09-19 12:01:44 +00:00
|
|
|
@mapping = Mapping.new(mapping_params)
|
2013-03-01 01:56:57 +00:00
|
|
|
|
2014-10-07 23:11:55 +00:00
|
|
|
@mapping.map.touch(:updated_at)
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
if @mapping.save
|
|
|
|
render json: @mapping, status: :created
|
|
|
|
else
|
|
|
|
render json: @mapping.errors, status: :unprocessable_entity
|
2013-03-01 00:56:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# PUT /mappings/1.json
|
2013-03-01 00:56:27 +00:00
|
|
|
def update
|
2014-07-27 19:57:35 +00:00
|
|
|
@mapping = Mapping.find(params[:id])
|
|
|
|
|
2014-10-07 23:11:55 +00:00
|
|
|
@mapping.map.touch(:updated_at)
|
|
|
|
|
2015-09-19 12:01:44 +00:00
|
|
|
if @mapping.update_attributes(mapping_params)
|
2014-07-27 19:57:35 +00:00
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: @mapping.errors, status: :unprocessable_entity
|
|
|
|
end
|
2013-03-01 00:56:27 +00:00
|
|
|
end
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# DELETE /mappings/1.json
|
2013-03-01 00:56:27 +00:00
|
|
|
def destroy
|
2014-07-27 19:57:35 +00:00
|
|
|
@mapping = Mapping.find(params[:id])
|
2014-10-07 23:11:55 +00:00
|
|
|
@map = @mapping.map
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
@mapping.destroy
|
|
|
|
|
2014-10-07 23:11:55 +00:00
|
|
|
@map.touch(:updated_at)
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
head :no_content
|
2013-03-01 00:56:27 +00:00
|
|
|
end
|
2015-09-19 08:26:34 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
|
|
def mapping_params
|
|
|
|
params.require(:mapping).permit(:id, :category, :xloc, :yloc, :topic_id, :synapse_id, :map_id, :user_id)
|
|
|
|
end
|
2014-10-07 23:11:55 +00:00
|
|
|
end
|