dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/devicecommand.go (about) 1 // 2 // Copyright (C) 2020-2023 IOTech Ltd 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 6 package dtos 7 8 import "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models" 9 10 type DeviceCommand struct { 11 Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string"` 12 IsHidden bool `json:"isHidden" yaml:"isHidden"` 13 ReadWrite string `json:"readWrite" yaml:"readWrite" validate:"oneof='R' 'W' 'RW' 'WR' ''"` 14 ResourceOperations []ResourceOperation `json:"resourceOperations" yaml:"resourceOperations" validate:"gt=0,dive"` 15 Tags map[string]any `json:"tags,omitempty" yaml:"tags,omitempty"` 16 } 17 18 type UpdateDeviceCommand struct { 19 Name *string `json:"name" validate:"required,edgex-dto-none-empty-string"` 20 IsHidden *bool `json:"isHidden"` 21 } 22 23 // ToDeviceCommandModel transforms the DeviceCommand DTO to the DeviceCommand model 24 func ToDeviceCommandModel(dto DeviceCommand) models.DeviceCommand { 25 resourceOperations := ToResourceOperationModels(dto.ResourceOperations) 26 27 return models.DeviceCommand{ 28 Name: dto.Name, 29 IsHidden: dto.IsHidden, 30 ReadWrite: dto.ReadWrite, 31 ResourceOperations: resourceOperations, 32 Tags: dto.Tags, 33 } 34 } 35 36 // ToDeviceCommandModels transforms the DeviceCommand DTOs to the DeviceCommand models 37 func ToDeviceCommandModels(deviceCommandDTOs []DeviceCommand) []models.DeviceCommand { 38 deviceCommandModels := make([]models.DeviceCommand, len(deviceCommandDTOs)) 39 for i, p := range deviceCommandDTOs { 40 deviceCommandModels[i] = ToDeviceCommandModel(p) 41 } 42 return deviceCommandModels 43 } 44 45 // FromDeviceCommandModelToDTO transforms the DeviceCommand model to the DeviceCommand DTO 46 func FromDeviceCommandModelToDTO(d models.DeviceCommand) DeviceCommand { 47 resourceOperations := make([]ResourceOperation, len(d.ResourceOperations)) 48 for i, ro := range d.ResourceOperations { 49 resourceOperations[i] = FromResourceOperationModelToDTO(ro) 50 } 51 return DeviceCommand{ 52 Name: d.Name, 53 IsHidden: d.IsHidden, 54 ReadWrite: d.ReadWrite, 55 ResourceOperations: resourceOperations, 56 Tags: d.Tags, 57 } 58 } 59 60 // FromDeviceCommandModelsToDTOs transforms the DeviceCommand models to the DeviceCommand DTOs 61 func FromDeviceCommandModelsToDTOs(deviceCommandModels []models.DeviceCommand) []DeviceCommand { 62 deviceCommandDTOs := make([]DeviceCommand, len(deviceCommandModels)) 63 for i, p := range deviceCommandModels { 64 deviceCommandDTOs[i] = FromDeviceCommandModelToDTO(p) 65 } 66 return deviceCommandDTOs 67 }