github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/operation/converter.go (about)

     1  package operation
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/model"
     5  	"github.com/kyma-incubator/compass/components/director/internal/repo"
     6  )
     7  
     8  type converter struct {
     9  }
    10  
    11  // NewConverter returns a new Converter that can later be used to make the conversions between the service and repository layer representations of an Operation.
    12  func NewConverter() *converter {
    13  	return &converter{}
    14  }
    15  
    16  // FromEntity converts the provided Entity repo-layer representation of an Operation to the service-layer representation model.Operation.
    17  func (c *converter) FromEntity(entity *Entity) *model.Operation {
    18  	return &model.Operation{
    19  		ID:         entity.ID,
    20  		OpType:     entity.Type,
    21  		Status:     model.OperationStatus(entity.Status),
    22  		Data:       repo.JSONRawMessageFromNullableString(entity.Data),
    23  		Error:      repo.JSONRawMessageFromNullableString(entity.Error),
    24  		Priority:   entity.Priority,
    25  		CreatedAt:  entity.CreatedAt,
    26  		FinishedAt: entity.FinishedAt,
    27  	}
    28  }
    29  
    30  // ToEntity converts the provided service-layer representation of an Operation to the repository-layer one.
    31  func (c *converter) ToEntity(operationModel *model.Operation) *Entity {
    32  	return &Entity{
    33  		ID:         operationModel.ID,
    34  		Type:       operationModel.OpType,
    35  		Status:     string(operationModel.Status),
    36  		Data:       repo.NewNullableStringFromJSONRawMessage(operationModel.Data),
    37  		Error:      repo.NewNullableStringFromJSONRawMessage(operationModel.Error),
    38  		Priority:   operationModel.Priority,
    39  		CreatedAt:  operationModel.CreatedAt,
    40  		FinishedAt: operationModel.FinishedAt,
    41  	}
    42  }