diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/terraform_http_backend_controller.rb | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/app/controllers/terraform_http_backend_controller.rb b/app/controllers/terraform_http_backend_controller.rb index e4d8c54..4d11961 100644 --- a/app/controllers/terraform_http_backend_controller.rb +++ b/app/controllers/terraform_http_backend_controller.rb @@ -21,24 +21,47 @@ class TerraformHttpBackendController < ApplicationController skip_before_action :verify_authenticity_token + def index + @all_states = TerraformState.all.group_by(&:state_id) + end + def create TerraformState.create( state_id: state_id, - data: params + data: params[:terraform_http_backend] ) render json: '{ "success": true }', status: 200 end def show - state = TerraformState.where( + @state = TerraformState.where( state_id: state_id - ).last + ).order(:id).last - if state.nil? + if @state.nil? render json: '{}', status: 404 else - render json: state.data, status: 200 + render json: @state.data, status: 200 + end + end + + def show_by_index + @state = TerraformState.where( + state_id: state_id + ).order(:id).to_a[params[:index].to_i] + + respond_to do |format| + format.html do + render :show + end + format.json do + if @state.nil? + render json: '{}', status: 404 + else + render json: @state.data, status: 200 + end + end end end |