dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/requests/deviceprofilebasicinfo.go (about) 1 // 2 // Copyright (C) 2022 IOTech Ltd 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 6 package requests 7 8 import ( 9 "encoding/json" 10 11 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common" 12 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos" 13 dtoCommon "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/common" 14 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/errors" 15 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models" 16 ) 17 18 // DeviceProfileBasicInfoRequest defines the Request Content for PATCH UpdateDeviceProfileBasicInfo DTO. 19 type DeviceProfileBasicInfoRequest struct { 20 dtoCommon.BaseRequest `json:",inline"` 21 BasicInfo dtos.UpdateDeviceProfileBasicInfo `json:"basicinfo"` 22 } 23 24 // Validate satisfies the Validator interface 25 func (d DeviceProfileBasicInfoRequest) Validate() error { 26 err := common.Validate(d) 27 return err 28 } 29 30 // UnmarshalJSON implements the Unmarshaler interface for the UpdateDeviceRequest type 31 func (d *DeviceProfileBasicInfoRequest) UnmarshalJSON(b []byte) error { 32 var alias struct { 33 dtoCommon.BaseRequest 34 BasicInfo dtos.UpdateDeviceProfileBasicInfo 35 } 36 if err := json.Unmarshal(b, &alias); err != nil { 37 return errors.NewCommonEdgeX(errors.KindContractInvalid, "Failed to unmarshal request body as JSON.", err) 38 } 39 40 *d = DeviceProfileBasicInfoRequest(alias) 41 42 // validate DeviceProfileBasicInfoRequest DTO 43 if err := d.Validate(); err != nil { 44 return err 45 } 46 return nil 47 } 48 49 // ReplaceDeviceProfileModelBasicInfoFieldsWithDTO replace existing DeviceProfile's basic info fields with DTO patch 50 func ReplaceDeviceProfileModelBasicInfoFieldsWithDTO(dp *models.DeviceProfile, patch dtos.UpdateDeviceProfileBasicInfo) { 51 if patch.Description != nil { 52 dp.Description = *patch.Description 53 } 54 if patch.Manufacturer != nil { 55 dp.Manufacturer = *patch.Manufacturer 56 } 57 if patch.Model != nil { 58 dp.Model = *patch.Model 59 } 60 if patch.Labels != nil { 61 dp.Labels = patch.Labels 62 } 63 }