func (r *GormWorkItemRepository) FindSecondItem(order *float64, secondItemDirection DirectionType) (*string, *float64, error) {
	Item := WorkItemStorage{}
	var tx *gorm.DB
	switch secondItemDirection {
	case DirectionAbove:
		// Finds the item above which reorder item has to be placed
		tx = r.db.Where(fmt.Sprintf("execution_order = (SELECT max(execution_order) FROM %s WHERE (execution_order < ?))", WorkItemStorage{}.TableName()), order).First(&Item)
	case DirectionBelow:
		// Finds the item below which reorder item has to be placed
		tx = r.db.Where(fmt.Sprintf("execution_order = (SELECT min(execution_order) FROM %s WHERE (execution_order > ?))", WorkItemStorage{}.TableName()), order).First(&Item)
	default:
		return nil, nil, nil
	}

	if tx.RecordNotFound() {
		// Item is placed at first or last position
		ItemId := strconv.FormatUint(Item.ID, 10)
		return &ItemId, nil, nil
	}
	if tx.Error != nil {
		return nil, nil, errors.NewInternalError(tx.Error.Error())
	}

	ItemId := strconv.FormatUint(Item.ID, 10)
	return &ItemId, &Item.ExecutionOrder, nil

}
// Reordering a workitem requires order of two closest workitems: above and below.
// FindSecondItem returns the order of the second workitem required to reorder.
// If direction == "above", then
//	FindFirstItem returns the value above which reorder item has to be placed
//      FindSecondItem returns the value below which reorder item has to be placed
// If direction == "below", then
//	FindFirstItem returns the value below which reorder item has to be placed
//      FindSecondItem returns the value above which reorder item has to be placed
Reordering a workitem requires order of two closest workitems: above and below.
FindSecondItem returns the order of the second workitem required to reorder.
If direction == "above", then
FindFirstItem returns the value above which reorder item has to be placed
FindSecondItem returns the value below which reorder item has to be placed
If direction == "below", then
FindFirstItem returns the value below which reorder item has to be placed
FindSecondItem returns the value above which reorder item has to be placed
// Reordering a workitem requires order of two closest workitems : above and below . // FindSecondItem returns the order of the second workitem required to reorder . // If direction == " above " then // FindFirstItem returns the value above which reorder item has to be placed // FindSecondItem returns the value below which reorder item has to be placed // If direction == " below " then // FindFirstItem returns the value below which reorder item has to be placed // FindSecondItem returns the value above which reorder item has to be placed
func (r *GormWorkItemRepository) FindSecondItem(order *float64, secondItemDirection DirectionType) (*string, *float64, error) {
	Item := WorkItemStorage{}
	var tx *gorm.DB
	switch secondItemDirection {
	case DirectionAbove:
		tx = r.db.Where(fmt.Sprintf("execution_order = (SELECT max(execution_order) FROM %s WHERE (execution_order < ?))", WorkItemStorage{}.TableName()), order).First(&Item)
	case DirectionBelow:
		tx = r.db.Where(fmt.Sprintf("execution_order = (SELECT min(execution_order) FROM %s WHERE (execution_order > ?))", WorkItemStorage{}.TableName()), order).First(&Item)
	default:
		return nil, nil, nil
	}
	if tx.RecordNotFound() {
		ItemId := strconv.FormatUint(Item.ID, 10)
		return &ItemId, nil, nil
	}
	if tx.Error != nil {
		return nil, nil, errors.NewInternalError(tx.Error.Error())
	}
	ItemId := strconv.FormatUint(Item.ID, 10)
	return &ItemId, &Item.ExecutionOrder, nil
}
func ( r * GormWorkItemRepository ) FindSecondItem ( order * float64 , secondItemDirection DirectionType ) ( * string , * float64 , error ) { Item := WorkItemStorage { } var tx * gorm . DB switch secondItemDirection { case DirectionAbove : tx = r . db . Where ( fmt . Sprintf ( " " , WorkItemStorage { } . TableName ( ) ) , order ) . First ( & Item ) case DirectionBelow : tx = r . db . Where ( fmt . Sprintf ( " " , WorkItemStorage { } . TableName ( ) ) , order ) . First ( & Item ) default : return nil , nil , nil } if tx . RecordNotFound ( ) { ItemId := strconv . FormatUint ( Item . ID , 10 ) return & ItemId , nil , nil } if tx . Error != nil { return nil , nil , errors . NewInternalError ( tx . Error . Error ( ) ) } ItemId := strconv . FormatUint ( Item . ID , 10 ) return & ItemId , & Item . ExecutionOrder , nil }
Reordering a workitem requires order of two closest workitems: above and below.
Reordering a workitem requires order of two closest workitems : above and below .
// Finds the item above which reorder item has to be placed // Finds the item below which reorder item has to be placed // Item is placed at first or last position