Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 4ddd2ad

Browse files
reidmitBrian Cunnie
andcommitted
V3: client can **see data** for a **service** usage event
We present the `service_guid` and `service_label` columns from the `service_usage_event` table as `service_offering.guid` and `service_offering.name` to reflect the new naming conventions across V3. Unlike the story, we do not display the organization name, it is not in the model (neither the app usage event model nor the service usage event model), and Greg has [agreed](https://cloudfoundry.slack.com/archives/CCRLX88DD/p1590701929419700) to not display it (V2 does not display the org name, either). [finishes #172985880] Co-authored-by: Reid Mitchell <rmitchell@pivotal.io> Co-authored-by: Brian Cunnie <bcunnie@pivotal.io>
1 parent ff1977c commit 4ddd2ad

4 files changed

Lines changed: 100 additions & 5 deletions

File tree

app/presenters/v3/usage_event_presenter.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def usage_event
2121
def build_data
2222
if usage_event.type == 'app'
2323
build_app_data
24+
else
25+
build_service_data
2426
end
2527
end
2628

@@ -63,5 +65,35 @@ def build_app_data
6365
}
6466
}
6567
end
68+
69+
def build_service_data
70+
{
71+
state: usage_event.state,
72+
space: {
73+
guid: usage_event.space_guid,
74+
name: usage_event.space_name,
75+
},
76+
organization: {
77+
guid: usage_event.org_guid,
78+
},
79+
service_instance: {
80+
guid: usage_event.service_instance_guid,
81+
name: usage_event.service_instance_name,
82+
type: usage_event.service_instance_type,
83+
},
84+
service_plan: {
85+
guid: usage_event.service_plan_guid,
86+
name: usage_event.service_plan_name,
87+
},
88+
service_offering: {
89+
guid: usage_event.service_guid,
90+
name: usage_event.service_label,
91+
},
92+
service_broker: {
93+
guid: usage_event.service_broker_guid,
94+
name: usage_event.service_broker_name,
95+
}
96+
}
97+
end
6698
end
6799
end

docs/v3/source/includes/api_resources/_usage_events.erb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"name": "name-1664"
2323
},
2424
"organization": {
25-
"guid": "guid-036444f4-f2f5-4ea8-a353-e73330ca0f0a",
26-
"name": "name-1665"
25+
"guid": "guid-036444f4-f2f5-4ea8-a353-e73330ca0f0a"
2726
},
2827
"buildpack": {
2928
"guid": "guid-34916716-31d7-40c1-9afd-f312996c9654",
@@ -50,6 +49,32 @@
5049
"created_at": "2020-05-28T12:34:56Z",
5150
"updated_at": "2020-05-28T12:34:56Z",
5251
"type": "service",
53-
"data": null
52+
"data": {
53+
"state": "CREATED",
54+
"space": {
55+
"guid": "guid-5e28f12f-9d80-473e-b826-537b148eb338",
56+
"name": "name-1664"
57+
},
58+
"organization": {
59+
"guid": "guid-036444f4-f2f5-4ea8-a353-e73330ca0f0a"
60+
},
61+
"service_instance": {
62+
"guid": "guid-f93250f7-7ef5-4b02-8d33-353919ce8358",
63+
"name": "name-1982",
64+
"type": "managed_service_instance"
65+
},
66+
"service_plan": {
67+
"guid": "guid-e9d2d5a0-69a6-46ef-bac5-43f3ed177614",
68+
"name": "name-1983"
69+
},
70+
"service_offering": {
71+
"guid": "guid-34916716-31d7-40c1-9afd-f312996c9654",
72+
"name": "label-64"
73+
},
74+
"service_broker": {
75+
"guid": "guid-7cc11646-bf38-4f4e-b6e0-9581916a74d9",
76+
"name": "name-2929"
77+
}
78+
}
5479
}
5580
<% end %>

spec/request/usage_events_spec.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,33 @@
9595
'created_at' => iso8601,
9696
'updated_at' => iso8601,
9797
'type' => 'service',
98-
'data' => nil
98+
'data' => {
99+
'state' => usage_event.state,
100+
'space' => {
101+
'guid' => usage_event.space_guid,
102+
'name' => usage_event.space_name,
103+
},
104+
'organization' => {
105+
'guid' => usage_event.org_guid,
106+
},
107+
'service_instance' => {
108+
'guid' => usage_event.service_instance_guid,
109+
'name' => usage_event.service_instance_name,
110+
'type' => usage_event.service_instance_type,
111+
},
112+
'service_plan' => {
113+
'guid' => usage_event.service_plan_guid,
114+
'name' => usage_event.service_plan_name,
115+
},
116+
'service_offering' => {
117+
'guid' => usage_event.service_guid,
118+
'name' => usage_event.service_label,
119+
},
120+
'service_broker' => {
121+
'guid' => usage_event.service_broker_guid,
122+
'name' => usage_event.service_broker_name,
123+
}
124+
}
99125
}
100126
end
101127

spec/unit/presenters/v3/usage_event_presenter_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@
4545
expect(result[:created_at]).to eq(usage_event.created_at)
4646
expect(result[:updated_at]).to eq(usage_event.updated_at)
4747
expect(result[:type]).to eq('service')
48-
expect(result[:data]).to be_nil
48+
expect(result[:data][:state]).to eq usage_event.state
49+
expect(result[:data][:space][:guid]).to eq usage_event.space_guid
50+
expect(result[:data][:space][:name]).to eq usage_event.space_name
51+
expect(result[:data][:organization][:guid]).to eq usage_event.org_guid
52+
expect(result[:data][:service_instance][:guid]).to eq usage_event.service_instance_guid
53+
expect(result[:data][:service_instance][:name]).to eq usage_event.service_instance_name
54+
expect(result[:data][:service_instance][:type]).to eq usage_event.service_instance_type
55+
expect(result[:data][:service_plan][:guid]).to eq usage_event.service_plan_guid
56+
expect(result[:data][:service_plan][:name]).to eq usage_event.service_plan_name
57+
expect(result[:data][:service_offering][:guid]).to eq usage_event.service_guid
58+
expect(result[:data][:service_offering][:name]).to eq usage_event.service_label
59+
expect(result[:data][:service_broker][:guid]).to eq usage_event.service_broker_guid
60+
expect(result[:data][:service_broker][:name]).to eq usage_event.service_broker_name
4961
end
5062
end
5163
end

0 commit comments

Comments
 (0)