Skip to content

Commit

Permalink
refactor: Rename PropertyValue struct to ResourceProperties
Browse files Browse the repository at this point in the history
Close #541

Signed-off-by: weichou <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Mar 11, 2021
1 parent 1c03d9d commit aae2b6e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
8 changes: 4 additions & 4 deletions v2/dtos/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var testDeviceProfile = models.DeviceProfile{
Description: TestDescription,
Tag: TestTag,
Attributes: testAttributes,
Properties: models.PropertyValue{
Properties: models.ResourceProperties{
ValueType: v2.ValueTypeInt16,
ReadWrite: v2.ReadWrite_RW,
},
Expand All @@ -60,7 +60,7 @@ func profileData() DeviceProfile {
Description: TestDescription,
Tag: TestTag,
Attributes: testAttributes,
Properties: PropertyValue{
Properties: ResourceProperties{
ValueType: v2.ValueTypeInt16,
ReadWrite: v2.ReadWrite_RW,
},
Expand Down Expand Up @@ -126,7 +126,7 @@ deviceResources:
-
name: "DeviceValue_Boolean_RW"
properties:
{ valueType: "Bool"}
{ valueType: "Bool", readWrite: "RW"}
deviceCommands:
-
name: "GenerateDeviceValue_Boolean_RW"
Expand All @@ -140,7 +140,7 @@ deviceResources:
-
name: "DeviceValue_Boolean_RW"
properties:
{ valueType: "Bool"}
{ valueType: "Bool", readWrite: "RW"}
deviceCommands:
-
name: "GenerateDeviceValue_Boolean_RW"
Expand Down
16 changes: 8 additions & 8 deletions v2/dtos/deviceresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"
// DeviceResource and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/DeviceResource
type DeviceResource struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
IsHidden bool `json:"isHidden,omitempty" yaml:"isHidden,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
Properties PropertyValue `json:"properties,omitempty" yaml:"properties,omitempty"`
Attributes map[string]string `json:"attributes,omitempty" yaml:"attributes,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
IsHidden bool `json:"isHidden,omitempty" yaml:"isHidden,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
Properties ResourceProperties `json:"properties,omitempty" yaml:"properties,omitempty"`
Attributes map[string]string `json:"attributes,omitempty" yaml:"attributes,omitempty"`
}

// ToDeviceResourceModel transforms the DeviceResource DTO to the DeviceResource model
Expand All @@ -25,7 +25,7 @@ func ToDeviceResourceModel(d DeviceResource) models.DeviceResource {
Name: d.Name,
IsHidden: d.IsHidden,
Tag: d.Tag,
Properties: ToPropertyValueModel(d.Properties),
Properties: ToResourcePropertiesModel(d.Properties),
Attributes: d.Attributes,
}
}
Expand All @@ -46,7 +46,7 @@ func FromDeviceResourceModelToDTO(d models.DeviceResource) DeviceResource {
Name: d.Name,
IsHidden: d.IsHidden,
Tag: d.Tag,
Properties: FromPropertyValueModelToDTO(d.Properties),
Properties: FromResourcePropertiesModelToDTO(d.Properties),
Attributes: d.Attributes,
}
}
Expand Down
2 changes: 1 addition & 1 deletion v2/dtos/protocolproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"
// ProtocolProperties contains the device connection information in key/value pair
type ProtocolProperties map[string]string

// ToPropertyValueModel transforms the ProtocolProperties DTO to the ProtocolProperties model
// ToProtocolPropertiesModel transforms the ProtocolProperties DTO to the ProtocolProperties model
func ToProtocolPropertiesModel(p ProtocolProperties) models.ProtocolProperties {
protocolProperties := make(models.ProtocolProperties)
for k, v := range p {
Expand Down
10 changes: 8 additions & 2 deletions v2/dtos/requests/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func profileData() DeviceProfileRequest {
Description: TestDescription,
Tag: TestTag,
Attributes: testAttributes,
Properties: dtos.PropertyValue{
Properties: dtos.ResourceProperties{
ValueType: v2.ValueTypeInt16,
ReadWrite: v2.ReadWrite_RW,
},
Expand Down Expand Up @@ -71,7 +71,7 @@ var expectedDeviceProfile = models.DeviceProfile{
Description: TestDescription,
Tag: TestTag,
Attributes: testAttributes,
Properties: models.PropertyValue{
Properties: models.ResourceProperties{
ValueType: v2.ValueTypeInt16,
ReadWrite: v2.ReadWrite_RW,
},
Expand All @@ -98,6 +98,10 @@ func TestDeviceProfileRequest_Validate(t *testing.T) {
noDeviceResourcePropertyType.Profile.DeviceResources[0].Properties.ValueType = emptyString
invalidDeviceResourcePropertyType := profileData()
invalidDeviceResourcePropertyType.Profile.DeviceResources[0].Properties.ValueType = "BadType"
noDeviceResourceReadWrite := profileData()
noDeviceResourceReadWrite.Profile.DeviceResources[0].Properties.ReadWrite = emptyString
invalidDeviceResourceReadWrite := profileData()
invalidDeviceResourceReadWrite.Profile.DeviceResources[0].Properties.ReadWrite = "invalid"

tests := []struct {
name string
Expand All @@ -110,6 +114,8 @@ func TestDeviceProfileRequest_Validate(t *testing.T) {
{"invalid DeviceProfileRequest, no deviceResource name", noDeviceResourceName, true},
{"invalid DeviceProfileRequest, no deviceResource property type", noDeviceResourcePropertyType, true},
{"invalid DeviceProfileRequest, invalid deviceResource property type", invalidDeviceResourcePropertyType, true},
{"invalid DeviceProfileRequest, no deviceResource property readWrite", noDeviceResourceReadWrite, true},
{"invalid DeviceProfileRequest, invalid deviceResource property readWrite", invalidDeviceResourcePropertyType, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
20 changes: 10 additions & 10 deletions v2/dtos/propertyvalue.go → v2/dtos/resourceproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package dtos

import "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/models"

// PropertyValue and its properties care defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/PropertyValue
type PropertyValue struct {
// ResourceProperties and its properties care defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/ResourceProperties
type ResourceProperties struct {
ValueType string `json:"valueType" yaml:"valueType" validate:"required,edgex-dto-value-type"`
ReadWrite string `json:"readWrite,omitempty" yaml:"readWrite,omitempty"`
ReadWrite string `json:"readWrite" yaml:"readWrite" validate:"required,oneof='R' 'W' 'RW'"`
Units string `json:"units,omitempty" yaml:"units,omitempty"`
Minimum string `json:"minimum,omitempty" yaml:"minimum,omitempty"`
Maximum string `json:"maximum,omitempty" yaml:"maximum,omitempty"`
Expand All @@ -25,9 +25,9 @@ type PropertyValue struct {
MediaType string `json:"mediaType,omitempty" yaml:"mediaType,omitempty"`
}

// ToPropertyValueModel transforms the PropertyValue DTO to the PropertyValue model
func ToPropertyValueModel(p PropertyValue) models.PropertyValue {
return models.PropertyValue{
// ToResourcePropertiesModel transforms the ResourceProperties DTO to the ResourceProperties model
func ToResourcePropertiesModel(p ResourceProperties) models.ResourceProperties {
return models.ResourceProperties{
ValueType: p.ValueType,
ReadWrite: p.ReadWrite,
Units: p.Units,
Expand All @@ -44,9 +44,9 @@ func ToPropertyValueModel(p PropertyValue) models.PropertyValue {
}
}

// FromPropertyValueModelToDTO transforms the PropertyValue Model to the PropertyValue DTO
func FromPropertyValueModelToDTO(p models.PropertyValue) PropertyValue {
return PropertyValue{
// FromResourcePropertiesModelToDTO transforms the ResourceProperties Model to the ResourceProperties DTO
func FromResourcePropertiesModelToDTO(p models.ResourceProperties) ResourceProperties {
return ResourceProperties{
ValueType: p.ValueType,
ReadWrite: p.ReadWrite,
Units: p.Units,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion v2/models/deviceresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ type DeviceResource struct {
Name string
IsHidden bool
Tag string
Properties PropertyValue
Properties ResourceProperties
Attributes map[string]string
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package models

// PropertyValue and its properties care defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/PropertyValue
// ResourceProperties and its properties care defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/ResourceProperties
// Model fields are same as the DTOs documented by this swagger. Exceptions, if any, are noted below.
type PropertyValue struct {
type ResourceProperties struct {
ValueType string
ReadWrite string
Units string
Expand Down

0 comments on commit aae2b6e

Please sign in to comment.