dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/link.go (about)

     1  package dtos
     2  
     3  import (
     4  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
     5  )
     6  
     7  type Link struct {
     8  	DBTimestamp `json:",inline"`
     9  	Id          string                 `json:"id,omitempty" validate:"omitempty,uuid"`
    10  	DeviceId    string                 `json:"device_id" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
    11  	TargetId    string                 `json:"target_id" validate:"omitempty"`
    12  	Properties  map[string]interface{} `json:"properties"`
    13  	Device      *Device                `json:"device,omitempty"`
    14  	Target      *Device                `json:"target,omitempty"`
    15  }
    16  
    17  // // ToLinkModel transforms the Link DTO to the Link Model
    18  func ToLinkModel(dto Link) models.Link {
    19  	var d models.Link
    20  	d.Id = dto.Id
    21  	d.DeviceId = dto.DeviceId
    22  	d.TargetId = dto.TargetId
    23  	d.Properties = dto.Properties
    24  	return d
    25  }
    26  
    27  // FromLinkModelToDTO transforms the Link Model to the Link DTO
    28  func FromLinkModelToDTO(d models.Link) Link {
    29  	var dto Link
    30  	dto.DBTimestamp = DBTimestamp(d.DBTimestamp)
    31  	dto.Id = d.Id
    32  	dto.Properties = d.Properties
    33  	dto.DeviceId = d.DeviceId
    34  	dto.TargetId = d.TargetId
    35  	if d.Device.Id != "" {
    36  		t := FromDeviceModelToDTO(d.Device)
    37  		dto.Device = &t
    38  	}
    39  	if d.Target.Id != "" {
    40  		t := FromDeviceModelToDTO(d.Target)
    41  		dto.Target = &t
    42  	}
    43  
    44  	return dto
    45  }
    46  
    47  // // UpdateDevice and its properties are defined in the APIv2 specification:
    48  // // https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/UpdateDevice
    49  type UpdateLink struct {
    50  	Id         string                 `json:"id,omitempty" validate:"omitempty,uuid"`
    51  	DeviceId   string                 `json:"device_id" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
    52  	TargetId   string                 `json:"target_id" validate:"omitempty"`
    53  	Properties map[string]interface{} `json:"properties"`
    54  }