backend/src/main/java/club/devcord/devmarkt/services/QuestionService.java
public QuestionResponse addQuestion(String templateName, String question, int number) {
    var templateIdOpt = templateRepo.getIdByName(templateName);
    if (templateIdOpt.isEmpty()) {
      return QuestionFailed.templateNotFound(templateName, number);
    }

    int templateId = templateIdOpt.get();
    if (number == -1) {
      number = questionRepo.getMaxNumberByTemplateId(templateId)
          .map(i -> i.intValue() + 1)
          .orElse(0);
    } else {
      reorderQuestions(templateId, number, 1);
    }

    var questionObj = new RawQuestion(-1, templateId, number, question);
    var questionSaved = questionRepo.save(questionObj);
    return new QuestionSuccess(questionSaved);
  }
/*
  If a number is provided (higher than -1), than the question will be inserted.
  In detail all numbers of the questions from the given number on
  are increased by 1 and the question is added on the given number.

  Examples:
  addQuestion(..., ..., -1): old, old, old -> old, old, old, new
  assQuestion(..., ..., 2) old, old, old -> old, old, new, old
   */
If a number is provided (higher than -1), than the question will be inserted.
In detail all numbers of the questions from the given number on
are increased by 1 and the question is added on the given number.


If a number is provided ( higher than - 1 ) than the question will be inserted . In detail all numbers of the questions from the given number on are increased by 1 and the question is added on the given number .
public QuestionResponse addQuestion(String templateName, String question, int number) {
    var templateIdOpt = templateRepo.getIdByName(templateName);
    if (templateIdOpt.isEmpty()) {
      return QuestionFailed.templateNotFound(templateName, number);
    }
    int templateId = templateIdOpt.get();
    if (number == -1) {
      number = questionRepo.getMaxNumberByTemplateId(templateId)
          .map(i -> i.intValue() + 1)
          .orElse(0);
    } else {
      reorderQuestions(templateId, number, 1);
    }
    var questionObj = new RawQuestion(-1, templateId, number, question);
    var questionSaved = questionRepo.save(questionObj);
    return new QuestionSuccess(questionSaved);
  }
public QuestionResponse addQuestion ( String templateName , String question , int number ) { var templateIdOpt = templateRepo . getIdByName ( templateName ) ; if ( templateIdOpt . isEmpty ( ) ) { return QuestionFailed . templateNotFound ( templateName , number ) ; } int templateId = templateIdOpt . get ( ) ; if ( number == - 1 ) { number = questionRepo . getMaxNumberByTemplateId ( templateId ) . map ( i -> i . intValue ( ) + 1 ) . orElse ( 0 ) ; } else { reorderQuestions ( templateId , number , 1 ) ; } var questionObj = new RawQuestion ( - 1 , templateId , number , question ) ; var questionSaved = questionRepo . save ( questionObj ) ; return new QuestionSuccess ( questionSaved ) ; }
If a number is provided (higher than -1), than the question will be inserted.
If a number is provided ( higher than - 1 ) than the question will be inserted .