def post(self):
        data = Exercise.parser.parse_args()
        user_id = data["userId"]
        description = data["description"]
        duration = data["duration"]
        if data["date"]:
            date = arrow.get(data["date"]).datetime
        else:
            date = arrow.utcnow().datetime

        new_exercise = ExerciseModel(user_id, description, duration, date)
        new_exercise.save_to_db()
        return new_exercise.json(), 201
 def get(self):
     data = parser.parse_args()
     body_part_id = data['body_part_id']
     user_id = data['user_id']
     return {
         "exercises": [
             exercise.json()
             for exercise in ExerciseModel.find_by_body_and_user(
                 body_part_id=body_part_id, user_id=user_id)
         ]
     }
 def get(self, exercise_name):
     parser = reqparse.RequestParser()
     parser.add_argument('user_id',
                         type=int,
                         required=True,
                         help="This field cannot be left blank")
     data = parser.parse_args()
     user_id = data['user_id']
     exercise = ExerciseModel.find_by_exercise_name_and_user(
         exercise_name=exercise_name, user_id=user_id)
     if exercise:
         return exercise.json()
     return {'message': 'exercise name not found'}, 404
Beispiel #4
0
    def post(self, topic):
        print(topic)
        if ExerciseModel.find_by_name(topic):
            return {
                'message':
                "A exercise with name '{}' already exists.".format(topic)
            }, 400

        exercise = ExerciseModel(topic)
        try:
            exercise.save_to_db()
        except:
            return {"message": "An error occurred creating the exercise."}, 500

        return exercise.json(), 201
 def get(self):
     data = ExerciseList.parser.parse_args()
     user_id = data["userId"]
     limit = data["limit"]
     if data["from"]:
         try:
             _from = arrow.get(data["from"])
         except:
             _from = None
     else:
         _from = None
     if data["to"]:
         try:
             to = arrow.get(data["to"])
         except:
             to = None
     else:
         to = None
     if not limit:
         limit = None
     raw_exercise_list = ExerciseModel.find_by_date_range(
         user_id, _from, to, limit)
     return list(map(convert_ExerciseModel_to_json, raw_exercise_list))
    def post(self, exercise_name):
        data = parser.parse_args()
        body_part_id = data['body_part_id']
        user_id = data['user_id']

        if ExerciseModel.find_by_exercise_name_and_user(
                exercise_name=exercise_name, user_id=user_id):
            return {
                "message":
                "The exercise name, {}, already exists.".format(exercise_name)
            }, 400

        exercise = ExerciseModel(exercise_name=exercise_name,
                                 body_part_id=body_part_id,
                                 user_id=user_id)
        try:
            exercise.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return exercise.json(), 201
Beispiel #7
0
 def get(self, topic):
     exercise = ExerciseModel.find_by_name(topic)
     if exercise:
         return exercise.json()
     return {'message': 'exercise not found'}, 404
Beispiel #8
0
    def delete(self, topic):
        name = ExerciseModel.find_by_name(topic)
        if name:
            name.delete_from_db()

        return {'message': 'exercise deleted'}
 def get(self):
     return {
         "exercises":
         [exercise.json() for exercise in ExerciseModel.find_all()]
     }