示例#1
0
class Game(Resource):
    def __init__(self):
        self._repository = Repository()
        self._validator = MovePieceValidator()

    def post(self):
        new_game = GameModel()
        uid = self._repository.insert(new_game)
        return {'uid': uid, 'game': new_game.to_dict()}, HTTPStatus.CREATED

    def get(self, uid):
        # if not uid:
        #     return 404
        return self._repository.fetch(uid).to_dict(), 200

    def patch(self, uid):
        req = reqparse.request
        body = req.get_json()

        success, errors = self._validator.validate(body)
        if not success:
            return {"errors": errors}, HTTPStatus.BAD_REQUEST

        game = self._repository.fetch(uid)

        if body['player'] != game.current_player_turn:
            # return 404
            pass

        piece = game.find_piece_at(*body['currentCoordinate'])
        if body['piece'] != piece.kind:
            # return 404
            pass
示例#2
0
def main(args):
    if '--debug' in args and args['--debug']:
        logger.setLevel('DEBUG')
    else:
        logger.setLevel('INFO')

    logger.info(app)

    repo = Repository(config, logger, args['--refresh'])
    citeproc = CiteProc(repo, config, logger)
    try:
        # start the citeproc server if the flag is passed
        if 'fetch' in args and args['fetch']:
            if len(args['TYPES']) > 0:
                repo.fetch(args['TYPES'])
            else:
                repo.fetch(config.default_types)

        elif 'make' in args and args['make']:
            citeproc.start()
            citeproc.build(args['OUTPUT_TYPES'])
    finally:
        # always try to shutdown the citeproc server
        citeproc.shutdown()