Skip to content

Commit

Permalink
feat: rename Resource to SourceName in AutoEvent model
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hung <chris@iotechsys.com>
  • Loading branch information
Chris Hung committed Feb 26, 2021
1 parent 8cf4766 commit 0ece284
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions v2/dtos/autoevent.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020 IOTech Ltd
// Copyright (C) 2020-2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -12,17 +12,17 @@ import (
// AutoEvent and its properties are defined in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/AutoEvent
type AutoEvent struct {
Frequency string `json:"frequency" validate:"required,edgex-dto-frequency"`
OnChange bool `json:"onChange,omitempty"`
Resource string `json:"resource" validate:"required"`
Frequency string `json:"frequency" validate:"required,edgex-dto-frequency"`
OnChange bool `json:"onChange,omitempty"`
SourceName string `json:"sourceName" validate:"required"`
}

// ToAutoEventModel transforms the AutoEvent DTO to the AutoEvent model
func ToAutoEventModel(a AutoEvent) models.AutoEvent {
return models.AutoEvent{
Frequency: a.Frequency,
OnChange: a.OnChange,
Resource: a.Resource,
Frequency: a.Frequency,
OnChange: a.OnChange,
SourceName: a.SourceName,
}
}

Expand All @@ -38,9 +38,9 @@ func ToAutoEventModels(autoEventDTOs []AutoEvent) []models.AutoEvent {
// FromAutoEventModelToDTO transforms the AutoEvent model to the AutoEvent DTO
func FromAutoEventModelToDTO(a models.AutoEvent) AutoEvent {
return AutoEvent{
Frequency: a.Frequency,
OnChange: a.OnChange,
Resource: a.Resource,
Frequency: a.Frequency,
OnChange: a.OnChange,
SourceName: a.SourceName,
}
}

Expand Down
8 changes: 4 additions & 4 deletions v2/dtos/requests/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
var testDeviceLabels = []string{"MODBUS", "TEMP"}
var testDeviceLocation = "{40lat;45long}"
var testAutoEvents = []dtos.AutoEvent{
{Resource: "TestDevice", Frequency: "300ms", OnChange: true},
{SourceName: "TestDevice", Frequency: "300ms", OnChange: true},
}
var testAutoEventsWithInvalidFrequency = []dtos.AutoEvent{
{Resource: "TestDevice", Frequency: "300", OnChange: true},
{SourceName: "TestDevice", Frequency: "300", OnChange: true},
}
var testProtocols = map[string]dtos.ProtocolProperties{
"modbus-ip": {
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestAddDeviceRequest_Validate(t *testing.T) {
noProtocols.Device.Protocols = map[string]dtos.ProtocolProperties{}
noAutoEventFrequency := testAddDevice
noAutoEventFrequency.Device.AutoEvents = []dtos.AutoEvent{
{Resource: "TestDevice", OnChange: true},
{SourceName: "TestDevice", OnChange: true},
}
noAutoEventResource := testAddDevice
noAutoEventResource.Device.AutoEvents = []dtos.AutoEvent{
Expand Down Expand Up @@ -228,7 +228,7 @@ func Test_AddDeviceReqToDeviceModels(t *testing.T) {
Labels: testDeviceLabels,
Location: testDeviceLocation,
AutoEvents: []models.AutoEvent{
{Resource: "TestDevice", Frequency: "300ms", OnChange: true},
{SourceName: "TestDevice", Frequency: "300ms", OnChange: true},
},
Protocols: map[string]models.ProtocolProperties{
"modbus-ip": {
Expand Down
6 changes: 3 additions & 3 deletions v2/dtos/requests/provisionwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func TestAddProvisionWatcherRequest_Validate(t *testing.T) {
noProfileName.ProvisionWatcher.ProfileName = emptyString
invalidFrequency := testAddProvisionWatcher
invalidFrequency.ProvisionWatcher.AutoEvents = []dtos.AutoEvent{
{Resource: "TestDevice", Frequency: "-1", OnChange: true},
{SourceName: "TestDevice", Frequency: "-1", OnChange: true},
}
noAutoEventFrequency := testAddProvisionWatcher
noAutoEventFrequency.ProvisionWatcher.AutoEvents = []dtos.AutoEvent{
{Resource: "TestDevice", OnChange: true},
{SourceName: "TestDevice", OnChange: true},
}
noAutoEventResource := testAddProvisionWatcher
noAutoEventResource.ProvisionWatcher.AutoEvents = []dtos.AutoEvent{
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestAddProvisionWatcherReqToProvisionWatcherModels(t *testing.T) {
ProfileName: TestDeviceProfileName,
AdminState: models.Locked,
AutoEvents: []models.AutoEvent{
{Resource: "TestDevice", Frequency: "300ms", OnChange: true},
{SourceName: "TestDevice", Frequency: "300ms", OnChange: true},
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions v2/models/autoevent.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020 IOTech Ltd
// Copyright (C) 2020-2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -9,7 +9,7 @@ package models
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.x#/AutoEvent
// Model fields are same as the DTOs documented by this swagger. Exceptions, if any, are noted below.
type AutoEvent struct {
Frequency string
OnChange bool
Resource string
Frequency string
OnChange bool
SourceName string
}

0 comments on commit 0ece284

Please sign in to comment.