Skip to content

Commit

Permalink
feat(deployed versions): add endpoint to list deployed versions for a…
Browse files Browse the repository at this point in the history
…n environment
  • Loading branch information
bethesque committed Feb 28, 2021
1 parent ce4b188 commit bd0ca9d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
54 changes: 54 additions & 0 deletions lib/pact_broker/api/resources/deployed_versions_for_environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'pact_broker/api/resources/base_resource'
require 'pact_broker/api/decorators/versions_decorator'

module PactBroker
module Api
module Resources
class DeployedVersionsForEnvironment < BaseResource
def content_types_accepted
[["application/json", :from_json]]
end

def content_types_provided
[["application/hal+json", :to_json]]
end

def allowed_methods
["GET", "OPTIONS"]
end

def resource_exists?
!!environment
end

def to_json
decorator_class(:deployed_versions_decorator).new(deployed_versions).to_json(decorator_options(title: title))
end

def policy_name
:'versions::versions'
end

private

attr_reader :deployed_versions

def environment
@environment ||= environment_service.find(environment_uuid)
end

def deployed_versions
@deployed_versions ||= deployed_version_service.find_deployed_versions_for_environment(environment)
end

def environment_uuid
identifier_from_path[:environment_uuid]
end

def title
"Deployed versions for #{environment.display_name}"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'pact_broker/api/resources/base_resource'
require 'pact_broker/configuration'
require 'pact_broker/api/decorators/versions_decorator'

module PactBroker
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/deployments/deployed_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def for_version_and_environment(version, environment)
where(version_id: version.id, environment_id: environment.id)
end

def for_environment(environment)
where(environment_id: environment.id)
end

def order_by_date_desc
order(Sequel.desc(:created_at), Sequel.desc(:id))
end
Expand Down
7 changes: 7 additions & 0 deletions lib/pact_broker/deployments/deployed_version_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def self.find_deployed_versions_for_version_and_environment(version, environment
.all
end

def self.find_deployed_versions_for_environment(environment)
DeployedVersion
.for_environment(environment)
.order_by_date_desc
.all
end

def self.record_previous_version_undeployed(pacticipant, environment)
DeployedVersion.last_deployed_version(pacticipant, environment)&.record_undeployed
end
Expand Down

0 comments on commit bd0ca9d

Please sign in to comment.