예제 #1
0
    def post(self, username):
        data = GameResource.parser.parse_args()

        if 'gameId' in data and data['gameId'] is not None:
            try:
                game = GameModel.find_by_id(data['gameId'])
                game.update_to_db(data['cellsState'], data['cellsClicked'],
                                  data['minutes'], data['seconds'],
                                  data['millis'], data['victory'],
                                  data['endGame'])
            except Exception as e:
                print(e)
                return {"message": "An error occurred updating the game."}, 500
        else:
            try:
                user = UserModel.find_by_username(username)
                game = GameModel(user.id, data['rows'], data['cols'],
                                 data['bombs'], data['board'],
                                 data['cellsState'], data['cellsClicked'],
                                 data['minutes'], data['seconds'],
                                 data['millis'], data['victory'],
                                 data['endGame'])
                game.save_to_db()
            except Exception as e:
                print(e)
                return {"message": "An error occurred creating the game."}, 500

        return game.json(), 201
예제 #2
0
    def get(self, _id):
        game = GameModel.find_by_id(_id)

        if game:
            return game.json()

        return {"message": "Item not found."}, 404
예제 #3
0
    def get(self, id):
        game = GameModel.find_by_id(id)

        if game:
            return game.json(), 200

        return {'message': 'Game with that ID not found'}, 404
예제 #4
0
    def delete(self, user_id, game_id):
        game = GameModel.find_by_id(game_id)
        user = UserModel.find_by_id(user_id)

        if game and user:
            user.remove_game_from_collection(game)
            return {'message': 'Game removed from collection!'}, 200

        return {'message': 'Game with that ID not found.'}, 404