예제 #1
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
예제 #2
0
 def get(self, topic):
     exercise = ExerciseModel.find_by_name(topic)
     if exercise:
         return exercise.json()
     return {'message': 'exercise not found'}, 404
예제 #3
0
    def delete(self, topic):
        name = ExerciseModel.find_by_name(topic)
        if name:
            name.delete_from_db()

        return {'message': 'exercise deleted'}