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
Exemplo n.º 2
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
Exemplo n.º 3
0
    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