dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/deviceservice.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 (
     9  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
    10  )
    11  
    12  type DeviceService struct {
    13  	DBTimestamp `json:",inline"`
    14  	Id          string   `json:"id,omitempty" validate:"omitempty,uuid"`
    15  	Name        string   `json:"name" validate:"required,edgex-dto-none-empty-string"`
    16  	Description string   `json:"description,omitempty"`
    17  	Labels      []string `json:"labels,omitempty"`
    18  	BaseAddress string   `json:"baseAddress" validate:"required,uri"`
    19  	AdminState  string   `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"`
    20  }
    21  
    22  type UpdateDeviceService struct {
    23  	Id          *string  `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
    24  	Name        *string  `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
    25  	Description *string  `json:"description"`
    26  	BaseAddress *string  `json:"baseAddress" validate:"omitempty,uri"`
    27  	Labels      []string `json:"labels"`
    28  	AdminState  *string  `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
    29  }
    30  
    31  // ToDeviceServiceModel transforms the DeviceService DTO to the DeviceService Model
    32  func ToDeviceServiceModel(dto DeviceService) models.DeviceService {
    33  	var ds models.DeviceService
    34  	ds.Id = dto.Id
    35  	ds.Name = dto.Name
    36  	ds.Description = dto.Description
    37  	ds.BaseAddress = dto.BaseAddress
    38  	ds.Labels = dto.Labels
    39  	ds.AdminState = models.AdminState(dto.AdminState)
    40  	return ds
    41  }
    42  
    43  // FromDeviceServiceModelToDTO transforms the DeviceService Model to the DeviceService DTO
    44  func FromDeviceServiceModelToDTO(ds models.DeviceService) DeviceService {
    45  	var dto DeviceService
    46  	dto.DBTimestamp = DBTimestamp(ds.DBTimestamp)
    47  	dto.Id = ds.Id
    48  	dto.Name = ds.Name
    49  	dto.Description = ds.Description
    50  	dto.BaseAddress = ds.BaseAddress
    51  	dto.Labels = ds.Labels
    52  	dto.AdminState = string(ds.AdminState)
    53  	return dto
    54  }
    55  
    56  // FromDeviceServiceModelToUpdateDTO transforms the DeviceService Model to the UpdateDeviceService DTO
    57  func FromDeviceServiceModelToUpdateDTO(ds models.DeviceService) UpdateDeviceService {
    58  	adminState := string(ds.AdminState)
    59  	dto := UpdateDeviceService{
    60  		Id:          &ds.Id,
    61  		Name:        &ds.Name,
    62  		Description: &ds.Description,
    63  		Labels:      ds.Labels,
    64  		BaseAddress: &ds.BaseAddress,
    65  		AdminState:  &adminState,
    66  	}
    67  	return dto
    68  }