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

     1  package requests
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common"
     7  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos"
     8  	dtoCommon "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/common"
     9  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/errors"
    10  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
    11  )
    12  
    13  type BulkOperationRequest struct {
    14  	dtoCommon.BaseRequest `json:",inline"`
    15  	Data                  dtos.BulkOperation `json:"data"`
    16  }
    17  
    18  // Validate satisfies the Validator interface
    19  func (b BulkOperationRequest) Validate() error {
    20  	err := common.Validate(b)
    21  	return err
    22  }
    23  
    24  // UnmarshalJSON implements the Unmarshaler interface for the AddDeviceRequest type
    25  func (b *BulkOperationRequest) UnmarshalJSON(by []byte) error {
    26  	var alias struct {
    27  		dtoCommon.BaseRequest
    28  		Data dtos.BulkOperation
    29  	}
    30  	if err := json.Unmarshal(by, &alias); err != nil {
    31  		return errors.NewCommonEdgeX(errors.KindContractInvalid, "Failed to unmarshal request body as JSON.", err)
    32  	}
    33  
    34  	*b = BulkOperationRequest(alias)
    35  
    36  	// validate AddDeviceRequest DTO
    37  	if err := b.Validate(); err != nil {
    38  		return err
    39  	}
    40  	return nil
    41  }
    42  func BulkOperationReqToModel(request BulkOperationRequest) models.BulkOperation {
    43  	return dtos.ToBulkOperationModel(request.Data, request.RequestId)
    44  }