Пример #1
0
  public boolean delete(TrainingModel model) {

    ArrayList<TrainingsExercises> allExercises =
        trainingsExercisesDao.getAllForTraining(model.getId());

    for (TrainingsExercises exercise : allExercises) {
      ArrayList<ExerciseSets> exerciseSets = exerciseSetsDao.getAllForExercise(exercise.getId());
      for (ExerciseSets exerciseSet : exerciseSets) {
        exerciseSetsDao.delete(exerciseSet.getId());
      }
      trainingsExercisesDao.delete(exercise.getId());
    }

    return trainingDao.delete(model.getId());
  }
Пример #2
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;
  }
Пример #3
0
  public TrainingExerciseModel addExerciseTo(TrainingModel training, ExerciseModel exercise) {

    TrainingsExercises trainingExercise = new TrainingsExercises();
    trainingExercise.setTrainingId(training.getId());
    trainingExercise.setExerciseId(exercise.getId());

    TrainingsExercises saved = trainingsExercisesDao.save(trainingExercise);

    if (saved != null) {
      TrainingExerciseModel model = new TrainingExerciseModel();
      model.setId(saved.getId());
      model.setTrainingId(saved.getTrainingId());
      model.setExerciseId(saved.getExerciseId());
      return model;
    }

    return null;
  }