def put(self, name): data = Game.parser.parse_args() game = GameModel.find_by_name(name) if game is None: game = GameModel(name, data['school_id']) else: game.school_id = data['school_id'] game.save_to_db() return game.json()
def post(self, name): status = 'failure' if GameModel.find_by_name(name): return {'message': "An item with name '{}' already exists".format(name)}, 400 # bad request. Error-first approach data = Game.parser.parse_args() game = GameModel(name, data['school_id']) # | try: game.save_to_db() status = 'success, game created' except: {'status': status, 'message': 'Some error occurred while inserting the game'}, 500 # Internal Server Error return {"game": game.json(), "status": status}, 201
def delete(self, name): game = GameModel.find_by_name(name) if game: game.delete_from_db() return {'message': 'Game deleted'} return {'message': 'Game not found'}
def get(self, name): game = GameModel.find_by_name(name) if game: return game.json() return {'message': 'Game not found'}, 404