backend/src/main/java/club/devcord/devmarkt/services/QuestionService.java
public void reorderQuestions(int templateId, int from, int offset) {
    var questions = questionRepo.findByTemplateIdAndNumberGreaterThanEqualsOrderByNumber(templateId,
        from);

    var updatedQuestions = new HashSet<RawQuestion>(questions.size());
    for (int i = 0; i < questions.size(); i++) {
      var question = questions.get(i);

      var num = i + from;

      int rightNum = num + offset;
      if (question.number() != rightNum) {
        updatedQuestions.add(
            new RawQuestion(question.id(), templateId, rightNum, question.question()));
      }
    }

    if (updatedQuestions.size() > 0) {
      questionRepo.deleteAll(updatedQuestions);
      questionRepo.saveAll(updatedQuestions);
    }
  }
/*
  Reorders (changes the number) of all questions with the given templateId, which
  numbers are out of the line to it's right order, optionally with an offset.
  Eg. 1, 2, 4 -> 1, 2, 3 (offset 0)
      1, 2, 4 -> 1, 2, 5 (offset 2)
   */
Reorders (changes the number) of all questions with the given templateId, which
numbers are out of the line to it's right order, optionally with an offset.
Eg.
Reorders ( changes the number ) of all questions with the given templateId which numbers are out of the line to it ' s right order optionally with an offset . Eg .
public void reorderQuestions(int templateId, int from, int offset) {
    var questions = questionRepo.findByTemplateIdAndNumberGreaterThanEqualsOrderByNumber(templateId,
        from);
    var updatedQuestions = new HashSet<RawQuestion>(questions.size());
    for (int i = 0; i < questions.size(); i++) {
      var question = questions.get(i);
      var num = i + from;
      int rightNum = num + offset;
      if (question.number() != rightNum) {
        updatedQuestions.add(
            new RawQuestion(question.id(), templateId, rightNum, question.question()));
      }
    }
    if (updatedQuestions.size() > 0) {
      questionRepo.deleteAll(updatedQuestions);
      questionRepo.saveAll(updatedQuestions);
    }
  }
public void reorderQuestions ( int templateId , int from , int offset ) { var questions = questionRepo . findByTemplateIdAndNumberGreaterThanEqualsOrderByNumber ( templateId , from ) ; var updatedQuestions = new HashSet < RawQuestion > ( questions . size ( ) ) ; for ( int i = 0 ; i < questions . size ( ) ; i ++ ) { var question = questions . get ( i ) ; var num = i + from ; int rightNum = num + offset ; if ( question . number ( ) != rightNum ) { updatedQuestions . add ( new RawQuestion ( question . id ( ) , templateId , rightNum , question . question ( ) ) ) ; } } if ( updatedQuestions . size ( ) > 0 ) { questionRepo . deleteAll ( updatedQuestions ) ; questionRepo . saveAll ( updatedQuestions ) ; } }
Reorders (changes the number) of all questions with the given templateId, which
numbers are out of the line to it's right order, optionally with an offset.
Reorders ( changes the number ) of all questions with the given templateId which numbers are out of the line to it ' s right order optionally with an offset .