func (r *GormWorkItemTypeRepository) Create(ctx context.Context, spaceID uuid.UUID, id *uuid.UUID, extendedTypeID *uuid.UUID, name string, description *string, icon string, fields map[string]FieldDefinition) (*WorkItemType, error) {
	// Make sure this WIT has an ID
	if id == nil {
		tmpID := uuid.NewV4()
		id = &tmpID
	}

	existing, _ := r.LoadTypeFromDB(ctx, *id)
	if existing != nil {
		log.Error(ctx, map[string]interface{}{"wit_id": *id}, "unable to create new work item type")
		return nil, errors.NewBadParameterError("name", *id)
	}

	allFields := map[string]FieldDefinition{}
	path := LtreeSafeID(*id)
	if extendedTypeID != nil {
		extendedType := WorkItemType{}
		db := r.db.Model(&extendedType).Where("id=?", extendedTypeID).First(&extendedType)
		if db.RecordNotFound() {
			return nil, errors.NewBadParameterError("extendedTypeID", *extendedTypeID)
		}
		if err := db.Error; err != nil {
			return nil, errors.NewInternalError(err.Error())
		}
		// copy fields from extended type
		for key, value := range extendedType.Fields {
			allFields[key] = value
		}
		path = extendedType.Path + pathSep + path
	}
	// now process new fields, checking whether they are already there.
	for field, definition := range fields {
		existing, exists := allFields[field]
		if exists && !compatibleFields(existing, definition) {
			return nil, fmt.Errorf("incompatible change for field %s", field)
		}
		allFields[field] = definition
	}

	created := WorkItemType{
		Version:     0,
		ID:          *id,
		Name:        name,
		Description: description,
		Icon:        icon,
		Path:        path,
		Fields:      allFields,
		SpaceID:     spaceID,
	}

	if err := r.db.Create(&created).Error; err != nil {
		return nil, errors.NewInternalError(err.Error())
	}

	log.Debug(ctx, map[string]interface{}{"witID": created.ID}, "Work item type created successfully!")
	return &created, 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 *GormWorkItemTypeRepository) Create(ctx context.Context, spaceID uuid.UUID, id *uuid.UUID, extendedTypeID *uuid.UUID, name string, description *string, icon string, fields map[string]FieldDefinition) (*WorkItemType, error) {
	if id == nil {
		tmpID := uuid.NewV4()
		id = &tmpID
	}
	existing, _ := r.LoadTypeFromDB(ctx, *id)
	if existing != nil {
		log.Error(ctx, map[string]interface{}{"wit_id": *id}, "unable to create new work item type")
		return nil, errors.NewBadParameterError("name", *id)
	}
	allFields := map[string]FieldDefinition{}
	path := LtreeSafeID(*id)
	if extendedTypeID != nil {
		extendedType := WorkItemType{}
		db := r.db.Model(&extendedType).Where("id=?", extendedTypeID).First(&extendedType)
		if db.RecordNotFound() {
			return nil, errors.NewBadParameterError("extendedTypeID", *extendedTypeID)
		}
		if err := db.Error; err != nil {
			return nil, errors.NewInternalError(err.Error())
		}
		for key, value := range extendedType.Fields {
			allFields[key] = value
		}
		path = extendedType.Path + pathSep + path
	}
	for field, definition := range fields {
		existing, exists := allFields[field]
		if exists && !compatibleFields(existing, definition) {
			return nil, fmt.Errorf("incompatible change for field %s", field)
		}
		allFields[field] = definition
	}
	created := WorkItemType{
		Version:     0,
		ID:          *id,
		Name:        name,
		Description: description,
		Icon:        icon,
		Path:        path,
		Fields:      allFields,
		SpaceID:     spaceID,
	}
	if err := r.db.Create(&created).Error; err != nil {
		return nil, errors.NewInternalError(err.Error())
	}
	log.Debug(ctx, map[string]interface{}{"witID": created.ID}, "Work item type created successfully!")
	return &created, nil
}
func ( r * GormWorkItemTypeRepository ) Create ( ctx context . Context , spaceID uuid . UUID , id * uuid . UUID , extendedTypeID * uuid . UUID , name string , description * string , icon string , fields map [ string ] FieldDefinition ) ( * WorkItemType , error ) { if id == nil { tmpID := uuid . NewV4 ( ) id = & tmpID } existing , _ := r . LoadTypeFromDB ( ctx , * id ) if existing != nil { log . Error ( ctx , map [ string ] interface { } { " " : * id } , " " ) return nil , errors . NewBadParameterError ( " " , * id ) } allFields := map [ string ] FieldDefinition { } path := LtreeSafeID ( * id ) if extendedTypeID != nil { extendedType := WorkItemType { } db := r . db . Model ( & extendedType ) . Where ( " " , extendedTypeID ) . First ( & extendedType ) if db . RecordNotFound ( ) { return nil , errors . NewBadParameterError ( " " , * extendedTypeID ) } if err := db . Error ; err != nil { return nil , errors . NewInternalError ( err . Error ( ) ) } for key , value := range extendedType . Fields { allFields [ key ] = value } path = extendedType . Path + pathSep + path } for field , definition := range fields { existing , exists := allFields [ field ] if exists && ! compatibleFields ( existing , definition ) { return nil , fmt . Errorf ( " " , field ) } allFields [ field ] = definition } created := WorkItemType { Version : 0 , ID : * id , Name : name , Description : description , Icon : icon , Path : path , Fields : allFields , SpaceID : spaceID , } if err := r . db . Create ( & created ) . Error ; err != nil { return nil , errors . NewInternalError ( err . Error ( ) ) } log . Debug ( ctx , map [ string ] interface { } { " " : created . ID } , " " ) return & created , 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
// Make sure this WIT has an ID // copy fields from extended type // now process new fields, checking whether they are already there.