Sha256: 5e90e186100e31a9b79fbc99b6610ca261434b24238b9dd3e2332022622cd497

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

# Controller for <%= name.capitalize%>
class <%= name.capitalize%>Controller < ApplicationController
  def index
    projects = <%= name.capitalize%>Repository.all
    # serialize here
  end

  def create
    contract = <%= name.capitalize%>Contract.new.call(request_params)
    if contract.failure?
      return render(
        code: 422, body: contract.errors.to_h.to_json,
        headers: { 'content-type' => 'application/json' }
      )
    end

    <%= name%> = <%= name.capitalize%>Repository.create(contract.to_h)
    render code: 201, body: <%= name%>.to_h.to_json, headers: { 'content-type' => 'application/json' }
  end

  def update
    contract = <%= name.capitalize%>Contract.new.call(request_params)
    if contract.success?
      <%= name.capitalize%>Repository.update(params[:id], contract.to_h)

      head 204
    else
      render code: 422, body: contract.errors
    end
  rescue ApplicationRepository::NotFoundRecord
    head 404
  end

  def delete
    <%= name.capitalize%>Repository.delete(params[:id])

    head 204
  rescue ApplicationRepository::NotFoundRecord
    head 404
  end

  def show
    <%= name%> = <%= name%>Repository.find(id: params[:id])
    #serialize here
  rescue ApplicationRepository::NotFoundRecord
    head 404
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mvc_one-0.1.0.pre.rc7 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc6 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc5 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc4 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc3 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc2 templates/app/controller_template.erb
mvc_one-0.1.0.pre.rc1 templates/app/controller_template.erb