Sha256: 24ad58bbbfd3dcf66746fb39dee9a4f22c15959258ccf9ce2b652e407fa3b8ee

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

class <%= controller_class_name %>Controller < ApplicationController

  SRID = <%= class_name %>.geometry_column.srid

<% unless options[:singleton] -%>
  # GET /<%= table_name %>
  def index
    @<%= table_name %> = <%= class_name %>.mapfish_filter(params)

    render :json => @<%= table_name %>.to_geojson
  end
<% end -%>

  # GET /<%= table_name %>/1
  def show
    @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>

    render :json => [@<%= file_name %>].to_geojson
  end

  # POST /<%= table_name %>
  def create
    @<%= table_name %> = []
    feature_collection = Geometry.from_geojson(request.raw_post, SRID)
    if feature_collection.nil?
      head :bad_request
      return
    end

    feature_collection.features.each do |feature|
      if feature.id.is_a? Integer
        <%= file_name %> = <%= orm_class.find(class_name, "feature.id") %>
      end
      if <%= file_name %>.nil?
        <%= file_name %> = <%= orm_class.build(class_name) %>
      end

      if <%= file_name %>.update_attributes_from_feature(feature)
        @<%= table_name %> << <%= file_name %>
      end
    end

    render :json => @<%= table_name %>.to_geojson, :status => :created
  end

  # PUT /<%= table_name %>/1
  def update
    feature = Geometry.from_geojson(request.raw_post, SRID)
    if feature.nil?
      head :bad_request
      return
    end

    if feature.id.is_a? Integer
      @<%= file_name %> = <%= orm_class.find(class_name, "feature.id") %>
    end
    if @<%= file_name %>.nil?
      head :not_found
      return
    end

    if @<%= file_name %>.update_attributes_from_feature(feature)
      render :json => @<%= file_name %>.to_geojson, :status => :created
    else
      head :unprocessable_entity
    end
  end

  # DELETE /<%= table_name %>/1
  def destroy
    @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
    @<%= orm_instance.destroy %>
    head :no_content
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mapfish-1.3.6 lib/generators/mapfish/resource/templates/controller.rb
mapfish-1.3.5 lib/generators/mapfish/resource/templates/controller.rb
mapfish-1.3.4 lib/generators/mapfish/resource/templates/controller.rb