class <%= name.classify.pluralize %>Endpoint < Grape::API namespace :<%= name.underscore.tableize %> do desc 'List existing <%= name.underscore.tableize %>' params do optional :page, type: Integer, default: 1, desc: 'Current page.' optional :size, type: Integer, default: 10, desc: 'Number of <%= name.underscore.tableize %> to return per page.' end get do conditions = {} paginate <%= name.classify %>, conditions: conditions, with: <%= name.classify.pluralize %>Presenter end desc 'Create new <%= name.underscore %>.' params do requires :<%= name.underscore %>, type: Hash do # Use this requires block to whitelist params which # may be updated via mass assignment at this endpoint. # # requires :name, type: String # optional :category, type: String end end post do create <%= name.classify %>, with: <%= name.classify %>Presenter, from: permitted_params[:<%= name.underscore %>] end desc 'Retrieve existing <%= name.underscore %>.' params do requires :id, desc: 'ID of the <%= name.underscore %>' end get ':id' do <%= name.underscore %> = <%= name.classify %>.find params[:id] present <%= name.underscore %>, with: <%= name.classify %>Presenter end desc 'Update existing <%= name.underscore %>.' params do requires :id, type: String, desc: '<%= name.classify %> id.' requires :<%= name.underscore %>, type: Hash do # Use this requires block to whitelist params which # may be updated via mass assignment at this endpoint. # # requires :name, type: String # optional :category, type: String end end patch ':id' do <%= name.underscore %> = <%= name.classify %>.find params[:id] update <%= name.underscore %>, with: <%= name.classify %>Presenter, from: permitted_params[:<%= name.underscore %>] end desc 'Delete existing <%= name.underscore %>.' params do requires :id, type: String, desc: '<%= name.classify %> id.' end delete ':id' do <%= name.underscore %> = <%= name.classify %>.find params[:id] delete <%= name.underscore %>, with: <%= name.classify %>Presenter end end end