func (r *GormWorkItemLinkRepository) Create(ctx context.Context, sourceID, targetID uint64, linkTypeID uuid.UUID, creatorID uuid.UUID) (*WorkItemLink, error) {
	link := &WorkItemLink{
		SourceID:   sourceID,
		TargetID:   targetID,
		LinkTypeID: linkTypeID,
	}
	if err := link.CheckValidForCreation(); err != nil {
		return nil, errs.WithStack(err)
	}
	if err := r.ValidateCorrectSourceAndTargetType(ctx, sourceID, targetID, linkTypeID); err != nil {
		return nil, errs.WithStack(err)
	}
	db := r.db.Create(link)
	if db.Error != nil {
		if gormsupport.IsUniqueViolation(db.Error, "work_item_links_unique_idx") {
			// TODO(kwk): Make NewBadParameterError a variadic function to avoid this ugliness ;)
			return nil, errors.NewBadParameterError("data.relationships.source_id + data.relationships.target_id + data.relationships.link_type_id", sourceID).Expected("unique")
		}
		return nil, errors.NewInternalError(db.Error.Error())
	}
	// save a revision of the created work item link
	if err := r.revisionRepo.Create(ctx, creatorID, RevisionTypeCreate, *link); err != nil {
		return nil, errs.Wrapf(err, "error while creating work item")
	}
	return link, nil
}
// Create creates a new work item link in the repository.
// Returns BadParameterError, ConversionError or InternalError
Create creates a new work item link in the repository.
Returns BadParameterError, ConversionError or InternalError
// Create creates a new work item link in the repository . // Returns BadParameterError ConversionError or InternalError
func (r *GormWorkItemLinkRepository) Create(ctx context.Context, sourceID, targetID uint64, linkTypeID uuid.UUID, creatorID uuid.UUID) (*WorkItemLink, error) {
	link := &WorkItemLink{
		SourceID:   sourceID,
		TargetID:   targetID,
		LinkTypeID: linkTypeID,
	}
	if err := link.CheckValidForCreation(); err != nil {
		return nil, errs.WithStack(err)
	}
	if err := r.ValidateCorrectSourceAndTargetType(ctx, sourceID, targetID, linkTypeID); err != nil {
		return nil, errs.WithStack(err)
	}
	db := r.db.Create(link)
	if db.Error != nil {
		if gormsupport.IsUniqueViolation(db.Error, "work_item_links_unique_idx") {
			return nil, errors.NewBadParameterError("data.relationships.source_id + data.relationships.target_id + data.relationships.link_type_id", sourceID).Expected("unique")
		}
		return nil, errors.NewInternalError(db.Error.Error())
	}
	if err := r.revisionRepo.Create(ctx, creatorID, RevisionTypeCreate, *link); err != nil {
		return nil, errs.Wrapf(err, "error while creating work item")
	}
	return link, nil
}
func ( r * GormWorkItemLinkRepository ) Create ( ctx context . Context , sourceID , targetID uint64 , linkTypeID uuid . UUID , creatorID uuid . UUID ) ( * WorkItemLink , error ) { link := & WorkItemLink { SourceID : sourceID , TargetID : targetID , LinkTypeID : linkTypeID , } if err := link . CheckValidForCreation ( ) ; err != nil { return nil , errs . WithStack ( err ) } if err := r . ValidateCorrectSourceAndTargetType ( ctx , sourceID , targetID , linkTypeID ) ; err != nil { return nil , errs . WithStack ( err ) } db := r . db . Create ( link ) if db . Error != nil { if gormsupport . IsUniqueViolation ( db . Error , " " ) { return nil , errors . NewBadParameterError ( " " , sourceID ) . Expected ( " " ) } return nil , errors . NewInternalError ( db . Error . Error ( ) ) } if err := r . revisionRepo . Create ( ctx , creatorID , RevisionTypeCreate , * link ) ; err != nil { return nil , errs . Wrapf ( err , " " ) } return link , nil }
Create creates a new work item link in the repository.
Create creates a new work item link in the repository .
// TODO(kwk): Make NewBadParameterError a variadic function to avoid this ugliness ;) // save a revision of the created work item link