func generateBacklogExpression(ctx context.Context, db application.DB, spaceID uuid.UUID, exp criteria.Expression) (criteria.Expression, error) {
	if exp != nil {
		exp = criteria.And(exp, criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed)))
	} else {
		exp = criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed))
	}

	err := application.Transactional(db, func(appl application.Application) error {
		// Get the root iteration
		iteration, err := appl.Iterations().RootIteration(ctx, spaceID)
		if err != nil {
			return errs.Wrap(err, "unable to fetch root iteration")
		}
		exp = criteria.Equals(criteria.Field(workitem.SystemIteration), criteria.Literal(iteration.ID.String()))

		// Get the list of work item types that derive of PlannerItem in the space
		var expWits criteria.Expression
		wits, err := appl.WorkItemTypes().ListPlannerItems(ctx, spaceID)
		if err != nil {
			return errs.Wrap(err, "unable to fetch work item types that derives of planner item")
		}
		if len(wits) >= 1 {
			expWits = criteria.Equals(criteria.Field("Type"), criteria.Literal(wits[0].ID.String()))
			for _, wit := range wits[1:] {
				witIDStr := wit.ID.String()
				expWits = criteria.Or(expWits, criteria.Equals(criteria.Field("Type"), criteria.Literal(witIDStr)))
			}
			exp = criteria.And(exp, expWits)
		}
		if len(wits) == 0 {
			// We set exp to nil to return an empty array
			exp = nil
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	return exp, nil
}
// generateBacklogExpression creates the expression to query for backlog items
generateBacklogExpression creates the expression to query for backlog items
// generateBacklogExpression creates the expression to query for backlog items
func generateBacklogExpression(ctx context.Context, db application.DB, spaceID uuid.UUID, exp criteria.Expression) (criteria.Expression, error) {
	if exp != nil {
		exp = criteria.And(exp, criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed)))
	} else {
		exp = criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed))
	}
	err := application.Transactional(db, func(appl application.Application) error {
		iteration, err := appl.Iterations().RootIteration(ctx, spaceID)
		if err != nil {
			return errs.Wrap(err, "unable to fetch root iteration")
		}
		exp = criteria.Equals(criteria.Field(workitem.SystemIteration), criteria.Literal(iteration.ID.String()))
		var expWits criteria.Expression
		wits, err := appl.WorkItemTypes().ListPlannerItems(ctx, spaceID)
		if err != nil {
			return errs.Wrap(err, "unable to fetch work item types that derives of planner item")
		}
		if len(wits) >= 1 {
			expWits = criteria.Equals(criteria.Field("Type"), criteria.Literal(wits[0].ID.String()))
			for _, wit := range wits[1:] {
				witIDStr := wit.ID.String()
				expWits = criteria.Or(expWits, criteria.Equals(criteria.Field("Type"), criteria.Literal(witIDStr)))
			}
			exp = criteria.And(exp, expWits)
		}
		if len(wits) == 0 {
			exp = nil
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return exp, nil
}
func generateBacklogExpression ( ctx context . Context , db application . DB , spaceID uuid . UUID , exp criteria . Expression ) ( criteria . Expression , error ) { if exp != nil { exp = criteria . And ( exp , criteria . Not ( criteria . Field ( workitem . SystemState ) , criteria . Literal ( workitem . SystemStateClosed ) ) ) } else { exp = criteria . Not ( criteria . Field ( workitem . SystemState ) , criteria . Literal ( workitem . SystemStateClosed ) ) } err := application . Transactional ( db , func ( appl application . Application ) error { iteration , err := appl . Iterations ( ) . RootIteration ( ctx , spaceID ) if err != nil { return errs . Wrap ( err , " " ) } exp = criteria . Equals ( criteria . Field ( workitem . SystemIteration ) , criteria . Literal ( iteration . ID . String ( ) ) ) var expWits criteria . Expression wits , err := appl . WorkItemTypes ( ) . ListPlannerItems ( ctx , spaceID ) if err != nil { return errs . Wrap ( err , " " ) } if len ( wits ) >= 1 { expWits = criteria . Equals ( criteria . Field ( " " ) , criteria . Literal ( wits [ 0 ] . ID . String ( ) ) ) for _ , wit := range wits [ 1 : ] { witIDStr := wit . ID . String ( ) expWits = criteria . Or ( expWits , criteria . Equals ( criteria . Field ( " " ) , criteria . Literal ( witIDStr ) ) ) } exp = criteria . And ( exp , expWits ) } if len ( wits ) == 0 { exp = nil } return nil } ) if err != nil { return nil , err } return exp , nil }
generateBacklogExpression creates the expression to query for backlog items
generateBacklogExpression creates the expression to query for backlog items
// Get the root iteration // Get the list of work item types that derive of PlannerItem in the space // We set exp to nil to return an empty array