Skip to content

Commit

Permalink
[MNOE-170] - Added an extra endpoint to create single app_instance
Browse files Browse the repository at this point in the history
  • Loading branch information
clemoberti committed Oct 20, 2016
1 parent d8be418 commit bd7ec97
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ class Jpi::V1::AppInstancesController < Jpi::V1::BaseResourceController

# GET /mnoe/jpi/v1/organization/1/apps.json?timestamp=151452452345
def index
@app_instances = parent_organization.app_instances.select do |i|
@app_instances = parent_organization.app_instances.select do |i|
i.active? && i.updated_at > Time.at(timestamp) && can?(:access,i)
end
end


# POST /mnoe/jpi/v1/organization/1/app_instances
def create
authorize! :manage_app_instances, parent_organization
app_instance = parent_organization.app_instances.create(product: params[:nid])
head :created
end

# DELETE /mnoe/jpi/v1/app_instances/1
def destroy
app_instance = MnoEnterprise::AppInstance.find(params[:id])
Expand All @@ -17,7 +24,7 @@ def destroy
MnoEnterprise::EventLogger.info('app_destroy', current_user.id, "App destroyed", app_instance.name,app_instance)
app_instance.terminate
end

head :accepted
end
end
Expand Down
2 changes: 1 addition & 1 deletion api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
end

# AppInstances
resources :app_instances, only: [:index, :destroy], shallow: true
resources :app_instances, only: [:index, :create, :destroy], shallow: true

# Teams
resources :teams, only: [:index, :show, :create, :update, :destroy], shallow: true do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
module MnoEnterprise
RSpec.describe Jpi::V1::AppInstancesController, type: :routing do
routes { MnoEnterprise::Engine.routes }

it 'routes to #index' do
expect(get('/jpi/v1/organizations/1/app_instances')).to route_to("mno_enterprise/jpi/v1/app_instances#index", organization_id: '1')
end

it 'routes to #create' do
expect(post('/jpi/v1/organizations/1/app_instances')).to route_to("mno_enterprise/jpi/v1/app_instances#create", organization_id: '1' )
end

it 'routes to #destroy' do
expect(delete('/jpi/v1/app_instances/1')).to route_to("mno_enterprise/jpi/v1/app_instances#destroy", id: '1' )
end
end
end

0 comments on commit bd7ec97

Please sign in to comment.