Пример #1
0
  public ExerciseSetModel addSetTo(TrainingExerciseModel model, int numberOfRepeats) {

    ArrayList<ExerciseSets> existingSets = exerciseSetsDao.getAllForExercise(model.getId());

    Exercise origEx = exerciseDao.getById(model.getExerciseId());
    Training origTr = trainingDao.getById(model.getTrainingId());

    ExerciseSets set = new ExerciseSets();
    set.setNumberOfRepeats(numberOfRepeats);
    set.setTrainingsExercisesId(model.getId());
    set.setOrder(existingSets.size() + 1);

    ExerciseSets saved = exerciseSetsDao.save(set);

    if (saved != null) {
      ExerciseSetModel exerciseSetModel = new ExerciseSetModel();
      exerciseSetModel.setId(saved.getId());
      exerciseSetModel.setNumberOfRepeats(saved.getNumberOfRepeats());
      exerciseSetModel.setOrder(saved.getOrder());
      exerciseSetModel.setTrainingsExercisesId(saved.getTrainingsExercisesId());
      return exerciseSetModel;
    }

    return null;
  }
Пример #2
0
  public boolean deleteLastSetFrom(TrainingExerciseModel model) {
    ArrayList<ExerciseSets> exerciseSets = exerciseSetsDao.getAllForExercise(model.getId());

    if (exerciseSets.size() < 1) {
      return false;
    }

    ExerciseSets lastSet = exerciseSets.get(0);

    for (ExerciseSets exerciseSet : exerciseSets) {
      if (lastSet.getOrder() < exerciseSet.getOrder()) {
        lastSet = exerciseSet;
      }
    }

    return exerciseSetsDao.delete(lastSet.getId());
  }
Пример #3
0
  public TrainingModel getById(int trainingId) {
    Training training = trainingDao.getById(trainingId);

    if (training == null) {
      return null;
    }

    TrainingModel model = new TrainingModel();
    model.setId(training.getId());
    model.setName(training.getName());
    model.setDescription(training.getDescription());
    model.setDateCreated(training.getDateCreated());

    ArrayList<TrainingsExercises> trainingsExercises =
        trainingsExercisesDao.getAllForTraining(trainingId);

    for (TrainingsExercises trainingExercise : trainingsExercises) {
      ExerciseModel exerciseModel = new ExerciseModel();
      exerciseModel.setId(trainingExercise.getId());

      Exercise exercise = exerciseDao.getById(trainingExercise.getExerciseId());
      exerciseModel.setName(exercise.getName());
      exerciseModel.setDescription(exercise.getDescription());
      exerciseModel.setImage(exercise.getImage());

      ArrayList<ExerciseSets> exerciseSets =
          exerciseSetsDao.getAllForExercise(trainingExercise.getId());

      for (ExerciseSets exerciseSet : exerciseSets) {
        ExerciseSetModel setModel = new ExerciseSetModel();
        setModel.setId(exerciseSet.getId());
        setModel.setNumberOfRepeats(exerciseSet.getNumberOfRepeats());
        setModel.setOrder(exerciseSet.getOrder());
        exerciseModel.addSet(setModel);
      }
      model.addExercise(exerciseModel);
    }

    return model;
  }