func (r *GormWorkItemRepository) Create(ctx context.Context, spaceID uuid.UUID, typeID uuid.UUID, fields map[string]interface{}, creatorID uuid.UUID) (*WorkItem, error) {
	wiType, err := r.witr.LoadTypeFromDB(ctx, typeID)
	if err != nil {
		return nil, errors.NewBadParameterError("typeID", typeID)
	}

	// The order of workitems are spaced by a factor of 1000.
	pos, err := r.LoadHighestOrder()
	if err != nil {
		return nil, errors.NewInternalError(err.Error())
	}
	pos = pos + orderValue
	wi := WorkItemStorage{
		Type:           typeID,
		Fields:         Fields{},
		ExecutionOrder: pos,
		SpaceID:        spaceID,
	}
	fields[SystemCreator] = creatorID.String()
	for fieldName, fieldDef := range wiType.Fields {
		if fieldName == SystemCreatedAt || fieldName == SystemUpdatedAt || fieldName == SystemOrder {
			continue
		}
		fieldValue := fields[fieldName]
		var err error
		wi.Fields[fieldName], err = fieldDef.ConvertToModel(fieldName, fieldValue)
		if err != nil {
			return nil, errors.NewBadParameterError(fieldName, fieldValue)
		}
		if fieldName == SystemDescription && wi.Fields[fieldName] != nil {
			description := rendering.NewMarkupContentFromMap(wi.Fields[fieldName].(map[string]interface{}))
			if !rendering.IsMarkupSupported(description.Markup) {
				return nil, errors.NewBadParameterError(fieldName, fieldValue)
			}
		}
	}
	tx := r.db
	if err = tx.Create(&wi).Error; err != nil {
		return nil, errs.Wrapf(err, "failed to create work item")
	}

	witem, err := ConvertWorkItemStorageToModel(wiType, &wi)
	if err != nil {
		return nil, err
	}
	// store a revision of the created work item
	err = r.wirr.Create(context.Background(), creatorID, RevisionTypeCreate, wi)
	if err != nil {
		return nil, errs.Wrapf(err, "error while creating work item")
	}
	log.Debug(ctx, map[string]interface{}{"pkg": "workitem", "wi_id": wi.ID}, "Work item created successfully!")
	return witem, nil
}
// Create creates a new work item in the repository
// returns BadParameterError, ConversionError or InternalError
Create creates a new work item in the repository
returns BadParameterError, ConversionError or InternalError
// Create creates a new work item in the repository // returns BadParameterError ConversionError or InternalError
func (r *GormWorkItemRepository) Create(ctx context.Context, spaceID uuid.UUID, typeID uuid.UUID, fields map[string]interface{}, creatorID uuid.UUID) (*WorkItem, error) {
	wiType, err := r.witr.LoadTypeFromDB(ctx, typeID)
	if err != nil {
		return nil, errors.NewBadParameterError("typeID", typeID)
	}
	pos, err := r.LoadHighestOrder()
	if err != nil {
		return nil, errors.NewInternalError(err.Error())
	}
	pos = pos + orderValue
	wi := WorkItemStorage{
		Type:           typeID,
		Fields:         Fields{},
		ExecutionOrder: pos,
		SpaceID:        spaceID,
	}
	fields[SystemCreator] = creatorID.String()
	for fieldName, fieldDef := range wiType.Fields {
		if fieldName == SystemCreatedAt || fieldName == SystemUpdatedAt || fieldName == SystemOrder {
			continue
		}
		fieldValue := fields[fieldName]
		var err error
		wi.Fields[fieldName], err = fieldDef.ConvertToModel(fieldName, fieldValue)
		if err != nil {
			return nil, errors.NewBadParameterError(fieldName, fieldValue)
		}
		if fieldName == SystemDescription && wi.Fields[fieldName] != nil {
			description := rendering.NewMarkupContentFromMap(wi.Fields[fieldName].(map[string]interface{}))
			if !rendering.IsMarkupSupported(description.Markup) {
				return nil, errors.NewBadParameterError(fieldName, fieldValue)
			}
		}
	}
	tx := r.db
	if err = tx.Create(&wi).Error; err != nil {
		return nil, errs.Wrapf(err, "failed to create work item")
	}
	witem, err := ConvertWorkItemStorageToModel(wiType, &wi)
	if err != nil {
		return nil, err
	}
	err = r.wirr.Create(context.Background(), creatorID, RevisionTypeCreate, wi)
	if err != nil {
		return nil, errs.Wrapf(err, "error while creating work item")
	}
	log.Debug(ctx, map[string]interface{}{"pkg": "workitem", "wi_id": wi.ID}, "Work item created successfully!")
	return witem, nil
}
func ( r * GormWorkItemRepository ) Create ( ctx context . Context , spaceID uuid . UUID , typeID uuid . UUID , fields map [ string ] interface { } , creatorID uuid . UUID ) ( * WorkItem , error ) { wiType , err := r . witr . LoadTypeFromDB ( ctx , typeID ) if err != nil { return nil , errors . NewBadParameterError ( " " , typeID ) } pos , err := r . LoadHighestOrder ( ) if err != nil { return nil , errors . NewInternalError ( err . Error ( ) ) } pos = pos + orderValue wi := WorkItemStorage { Type : typeID , Fields : Fields { } , ExecutionOrder : pos , SpaceID : spaceID , } fields [ SystemCreator ] = creatorID . String ( ) for fieldName , fieldDef := range wiType . Fields { if fieldName == SystemCreatedAt || fieldName == SystemUpdatedAt || fieldName == SystemOrder { continue } fieldValue := fields [ fieldName ] var err error wi . Fields [ fieldName ] , err = fieldDef . ConvertToModel ( fieldName , fieldValue ) if err != nil { return nil , errors . NewBadParameterError ( fieldName , fieldValue ) } if fieldName == SystemDescription && wi . Fields [ fieldName ] != nil { description := rendering . NewMarkupContentFromMap ( wi . Fields [ fieldName ] . ( map [ string ] interface { } ) ) if ! rendering . IsMarkupSupported ( description . Markup ) { return nil , errors . NewBadParameterError ( fieldName , fieldValue ) } } } tx := r . db if err = tx . Create ( & wi ) . Error ; err != nil { return nil , errs . Wrapf ( err , " " ) } witem , err := ConvertWorkItemStorageToModel ( wiType , & wi ) if err != nil { return nil , err } err = r . wirr . Create ( context . Background ( ) , creatorID , RevisionTypeCreate , wi ) if err != nil { return nil , errs . Wrapf ( err , " " ) } log . Debug ( ctx , map [ string ] interface { } { " " : " " , " " : wi . ID } , " " ) return witem , nil }
Create creates a new work item in the repository
returns BadParameterError, ConversionError or InternalError
Create creates a new work item in the repository returns BadParameterError ConversionError or InternalError
// The order of workitems are spaced by a factor of 1000. // store a revision of the created work item