-
Notifications
You must be signed in to change notification settings - Fork 28
/
service_plan.go
85 lines (77 loc) · 2.56 KB
/
service_plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright 2018 The Service Manager Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package postgres
import (
"github.com/Peripli/service-manager/pkg/types"
"github.com/Peripli/service-manager/storage"
sqlxtypes "github.com/jmoiron/sqlx/types"
)
//go:generate smgen storage ServicePlan github.com/Peripli/service-manager/pkg/types
type ServicePlan struct {
BaseEntity
Name string `db:"name"`
Description string `db:"description"`
Free bool `db:"free"`
Bindable bool `db:"bindable"`
PlanUpdatable bool `db:"plan_updateable"`
CatalogID string `db:"catalog_id"`
CatalogName string `db:"catalog_name"`
Metadata sqlxtypes.JSONText `db:"metadata"`
Schemas sqlxtypes.JSONText `db:"schemas"`
ServiceOfferingID string `db:"service_offering_id"`
}
func (sp *ServicePlan) ToObject() types.Object {
return &types.ServicePlan{
Base: types.Base{
ID: sp.ID,
CreatedAt: sp.CreatedAt,
UpdatedAt: sp.UpdatedAt,
},
Name: sp.Name,
Description: sp.Description,
CatalogID: sp.CatalogID,
CatalogName: sp.CatalogName,
Free: sp.Free,
Bindable: sp.Bindable,
PlanUpdatable: sp.PlanUpdatable,
Metadata: getJSONRawMessage(sp.Metadata),
Schemas: getJSONRawMessage(sp.Schemas),
ServiceOfferingID: sp.ServiceOfferingID,
}
}
func (sp *ServicePlan) FromObject(object types.Object) (storage.Entity, bool) {
plan, ok := object.(*types.ServicePlan)
if !ok {
return nil, false
}
return &ServicePlan{
BaseEntity: BaseEntity{
ID: plan.ID,
CreatedAt: plan.CreatedAt,
UpdatedAt: plan.UpdatedAt,
},
Name: plan.Name,
Description: plan.Description,
Free: plan.Free,
Bindable: plan.Bindable,
PlanUpdatable: plan.PlanUpdatable,
CatalogID: plan.CatalogID,
CatalogName: plan.CatalogName,
Metadata: getJSONText(plan.Metadata),
Schemas: getJSONText(plan.Schemas),
ServiceOfferingID: plan.ServiceOfferingID,
}, true
}