Exemple #1
0
    def create(name: str,
               age: int,
               weight: float,
               human: bool,
               hat_id: int = None) -> dict:
        """ Create character """
        result: dict = {}
        try:
            # if hat_id is not None, check if exists, throw exception instead
            if hat_id is not None:
                hat = HatModel.query.get(hat_id)
                if hat is None:
                    raise ResourceDoesNotExist(
                        "Hat {} does not exist".format(hat_id))

            character = CharacterModel(name=name,
                                       age=age,
                                       weight=weight,
                                       human=human,
                                       hat_id=hat_id)
            character.save()

            result = {
                'id': character.id,
                'name': character.name,
                'age': character.age,
                'weight': character.weight,
                'human': character.human,
                'hat_id': character.hat_id,
            }
        except IntegrityError:
            CharacterModel.rollback()
            # raise ResourceExists('Character already exists')

        return result
Exemple #2
0
def create(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    data = json.loads(event.get('body'))

    character = CharacterModel(id=str(uuid4()),
                               name=data.get('name'),
                               account=data.get('account', 'None'),
                               player_class=int(data.get('player_class')),
                               created_at=datetime.utcnow())

    character.save()

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response
Exemple #3
0
    # character = get(request, None)

    # print()
    # print()
    # print(character['body'])

    # print()
    # print('All characters')

    # response = list(None, None)

    # print(response)

    character_1 = CharacterModel(name='Angst')

    character_1.save()

    print(character_1)

    character_1.add_item(
        InventoryItemMap(id=str(uuid4()),
                         slot=1,
                         slot_name='Head',
                         damage=21,
                         crit_chance=.025))
    character_1.save()
    print()
    print(character_1)

    character_1.add_item(
        InventoryItemMap(id=str(uuid4()),