11require 'presenters/v3/base_presenter'
22require 'presenters/mixins/metadata_presentation_helpers'
3+ require 'presenters/helpers/quota_presenter_builder'
34
45module VCAP ::CloudController ::Presenters ::V3
56 class OrganizationQuotaPresenter < BasePresenter
@@ -16,59 +17,42 @@ def initialize(
1617 end
1718
1819 def to_hash
19- {
20- guid : organization_quota . guid ,
21- created_at : organization_quota . created_at ,
22- updated_at : organization_quota . updated_at ,
23- name : organization_quota . name ,
24- apps : {
25- total_memory_in_mb : convert_unlimited_to_nil ( organization_quota . memory_limit ) ,
26- per_process_memory_in_mb : convert_unlimited_to_nil ( organization_quota . instance_memory_limit ) ,
27- total_instances : convert_unlimited_to_nil ( organization_quota . app_instance_limit ) ,
28- per_app_tasks : convert_unlimited_to_nil ( organization_quota . app_task_limit ) ,
29- log_rate_limit_in_bytes_per_second : convert_unlimited_to_nil ( organization_quota . log_rate_limit )
30- } ,
31- services : {
32- paid_services_allowed : organization_quota . non_basic_services_allowed ,
33- total_service_instances : convert_unlimited_to_nil ( organization_quota . total_services ) ,
34- total_service_keys : convert_unlimited_to_nil ( organization_quota . total_service_keys )
35- } ,
36- routes : {
37- total_routes : convert_unlimited_to_nil ( organization_quota . total_routes ) ,
38- total_reserved_ports : convert_unlimited_to_nil ( organization_quota . total_reserved_route_ports )
39- } ,
40- domains : {
41- total_domains : convert_unlimited_to_nil ( organization_quota . total_private_domains )
42- } ,
43- relationships : {
44- organizations : {
45- data : filtered_visible_orgs
46- }
47- } ,
48- links : build_links
49- }
20+ builder = VCAP ::CloudController ::Presenters ::QuotaPresenterBuilder . new ( quota )
21+ builder . add_resource_limits .
22+ add_domains .
23+ add_relationships ( relationships ) .
24+ add_links ( build_links )
25+ builder . build
5026 end
5127
5228 private
5329
54- def filtered_visible_orgs
55- ds = organization_quota . organizations_dataset
56- ds = ds . where ( guid : @visible_org_guids_query ) unless @all_orgs_visible
57- ds . select_map ( :guid ) . map { |g | { guid : g } }
30+ def quota
31+ @resource
5832 end
5933
60- def organization_quota
61- @resource
34+ def relationships
35+ {
36+ organizations : {
37+ data : filtered_visible_orgs
38+ }
39+ }
6240 end
6341
64- def convert_unlimited_to_nil ( value )
65- value == -1 ? nil : value
42+ def filtered_visible_orgs
43+ ds = quota . organizations_dataset
44+ ds = ds . where ( guid : @visible_org_guids_query ) unless @all_orgs_visible
45+ ds . select_map ( :guid ) . map { |g | { guid : g } }
6646 end
6747
6848 def build_links
6949 {
70- self : { href : url_builder . build_url ( path : "/v3/organization_quotas/#{ organization_quota . guid } " ) }
50+ self : { href : url_builder . build_url ( path : "/v3/organization_quotas/#{ quota . guid } " ) }
7151 }
7252 end
53+
54+ def unlimited_to_nil ( value )
55+ value == -1 ? nil : value
56+ end
7357 end
7458end
0 commit comments