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

     1  //
     2  // Copyright (C) 2021 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 IntervalAction struct {
    13  	DBTimestamp  `json:",inline"`
    14  	Id           string  `json:"id,omitempty" validate:"omitempty,uuid"`
    15  	Name         string  `json:"name" validate:"edgex-dto-none-empty-string"`
    16  	IntervalName string  `json:"intervalName" validate:"edgex-dto-none-empty-string"`
    17  	Address      Address `json:"address" validate:"required"`
    18  	Content      string  `json:"content,omitempty"`
    19  	ContentType  string  `json:"contentType,omitempty"`
    20  	AdminState   string  `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"`
    21  	AuthMethod   string  `json:"authMethod" validate:"oneof='' 'NONE' 'JWT'"`
    22  }
    23  
    24  // NewIntervalAction creates intervalAction DTO with required fields
    25  func NewIntervalAction(name string, intervalName string, address Address) IntervalAction {
    26  	return IntervalAction{
    27  		Name:         name,
    28  		IntervalName: intervalName,
    29  		Address:      address,
    30  		AdminState:   models.Unlocked,
    31  	}
    32  }
    33  
    34  type UpdateIntervalAction struct {
    35  	Id           *string  `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
    36  	Name         *string  `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
    37  	IntervalName *string  `json:"intervalName" validate:"omitempty,edgex-dto-none-empty-string"`
    38  	Content      *string  `json:"content"`
    39  	ContentType  *string  `json:"contentType"`
    40  	Address      *Address `json:"address"`
    41  	AdminState   *string  `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
    42  	AuthMethod   *string  `json:"authMethod" validate:"omitempty,oneof='' 'NONE' 'JWT'"`
    43  }
    44  
    45  // NewUpdateIntervalAction creates updateIntervalAction DTO with required field
    46  func NewUpdateIntervalAction(name string) UpdateIntervalAction {
    47  	return UpdateIntervalAction{Name: &name}
    48  }
    49  
    50  // ToIntervalActionModel transforms the IntervalAction DTO to the IntervalAction Model
    51  func ToIntervalActionModel(dto IntervalAction) models.IntervalAction {
    52  	var model models.IntervalAction
    53  	model.Id = dto.Id
    54  	model.Name = dto.Name
    55  	model.IntervalName = dto.IntervalName
    56  	model.Content = dto.Content
    57  	model.ContentType = dto.ContentType
    58  	model.Address = ToAddressModel(dto.Address)
    59  	model.AdminState = models.AdminState(dto.AdminState)
    60  	model.AuthMethod = models.AuthMethod(dto.AuthMethod)
    61  	return model
    62  }
    63  
    64  // FromIntervalActionModelToDTO transforms the IntervalAction Model to the IntervalAction DTO
    65  func FromIntervalActionModelToDTO(model models.IntervalAction) IntervalAction {
    66  	var dto IntervalAction
    67  	dto.DBTimestamp = DBTimestamp(model.DBTimestamp)
    68  	dto.Id = model.Id
    69  	dto.Name = model.Name
    70  	dto.IntervalName = model.IntervalName
    71  	dto.Content = model.Content
    72  	dto.ContentType = model.ContentType
    73  	dto.Address = FromAddressModelToDTO(model.Address)
    74  	dto.AdminState = string(model.AdminState)
    75  	dto.AuthMethod = string(model.AuthMethod)
    76  	return dto
    77  }