def delete(id):
    """
    Deletes an existing check-in counter from the system
    ---
    parameters:
        -   in: path
            name: id
            required: true
            schema:
                type: number
                example: 1
            description: ID of the check-in counter
    responses:
        200:
            description: Deleted the check-in counter from the system
            schema:
                $ref: "#/definitions/CheckInCounter"
        400:
            description: The given counter id is invalid
    """
    # Check if input is a number
    try:
        int(id)
    except ValueError:
        return 'Invalid id \"' + id + '\"', 400

    # Check if input number is smaller than 32 bit int
    if not abs(int(id)) <= 0xffffffff:
        return 'Invalid id \"' + id + '\"', 400

    # Check if check-in counter with given id exists
    if CheckInCounter.get(id=id) is None:
        return 'Check-in counter with id ' + id + ' does not exist', 400

    counter = CheckInCounter[id]
    counter_old = counter.to_dict(
    )  # Make dictionary of old counter object before its deletion
    counter.delete()

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'Check-in counter has been deleted successfully',
        'from': 'check_in_counter_management',
        'type': 'DELETE',
        'data': {},
        'old_data': counter_old
    }

    msg_handler.send_message_to_exchange('check-in-counter',
                                         json.dumps(payload))

    return 'Succeeded'
Exemplo n.º 2
0
def delete(id):
    """
    Deletes an existing gate from the system
    ---
    parameters:
        -   in: path
            name: id
            required: true
            schema:
                type: number
                example: 1
            description: ID of the gate
    responses:
        200:
            description: Deleted the gate from the system
            schema:
                $ref: "#/definitions/Gate"
        400:
            description: The given gate id is invalid
    """
    # Check if input is a number
    try:
        int(id)
    except ValueError:
        return 'Invalid id \"' + id + '\"'

    # Check if input number is smaller than 32 bit int
    if not abs(int(id)) <= 0xffffffff:
        return 'Invalid id \"' + id + '\"'

    # Check if gate with given id exists
    if Gate.get(id=id) is None:
        return 'Gate with id ' + id + ' does not exist', 400

    gate = Gate[id]
    gate_old = gate.to_dict(
    )  # Make dictionary of old gate object before its deletion
    gate.delete()

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'Gate has been deleted successfully',
        'from': 'gate_management',
        'type': 'DELETE',
        'data': {},
        'old_data': gate_old
    }

    msg_handler.send_message_to_exchange('gate', json.dumps(payload))

    return 'Succeeded'
Exemplo n.º 3
0
def create():
    """
    Adds a gate to the system
    ---
    parameters:
        -   in: body
            name: gate
            description: The gate to create
            schema:
                type: object
                properties:
                    terminal:
                        type: string
                        description: Terminal of the gate
                        example: 'A'
                    number:
                        type: integer
                        description: Number of the gate
                        example: 1
    responses:
        200:
            description: Created a new gate
            schema:
                $ref: "#/definitions/Gate"
    """
    gate = json.loads(request.data.decode('UTF-8'))

    new_gate = Gate(**gate)

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'New gate has been added successfully',
        'from': 'gate_management',
        'type': 'CREATE',
        'data': new_gate.to_dict(),
        'old_data': {}
    }

    msg_handler.send_message_to_exchange('gate', json.dumps(payload))

    return json.dumps(new_gate.to_dict())
def create():
    """
    Adds a check-in counter to the system
    ---
    parameters:
        -   in: body
            name: counter
            description: The check-in counter to create
            schema:
                type: object
                properties:
                    number:
                        type: integer
                        description: Number of the check-in counter
                        example: 4
    responses:
        200:
            description: Created a new check-in counter
            schema:
                $ref: "#/definitions/CheckInCounter"
    """
    counter = json.loads(request.data.decode('UTF-8'))

    new_counter = CheckInCounter(**counter)

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'New check-in counter has been added successfully',
        'from': 'check_in_counter_management',
        'type': 'CREATE',
        'data': new_counter.to_dict(),
        'old_data': {}
    }

    msg_handler.send_message_to_exchange('check-in-counter',
                                         json.dumps(payload))

    return json.dumps(new_counter.to_dict())
Exemplo n.º 5
0
def update(id):
    """
    Updates an existing gate in the system
    ---
    parameters:
        -   in: path
            name: id
            required: true
            schema:
                type: number
                example: 1
            description: ID of the gate
        -   in: body
            name: gate
            required: true
            schema:
                type: object
                properties:
                    terminal:
                        type: string
                        description: Terminal of the gate
                        example: 'A'
                    number:
                        type: integer
                        description: Number of the gate
                        example: 1
            description: The attributes of the gate to update
    responses:
        200:
            description: Updated the gate
            schema:
                $ref: "#/definitions/Gate"
        400:
            description: The given gate id is invalid
    """
    # Check if input is a number
    try:
        int(id)
    except ValueError:
        return 'Invalid id \"' + id + '\"'

    # Check if input number is smaller than 32 bit int
    if not abs(int(id)) <= 0xffffffff:
        return 'Invalid id \"' + id + '\"'

    # Check if gate with given id exists
    if Gate.get(id=id) is None:
        return 'Gate with id ' + id + ' does not exist', 400

    gate_update = json.loads(request.data.decode('UTF-8'))
    gate = Gate[id]
    gate_old = gate.to_dict(
    )  # Make dictionary of old gate object before updating it
    gate.update_props(gate_update)

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'Gate has been updated successfully',
        'from': 'game_management',
        'type': 'PUT',
        'data': gate.to_dict(),
        'old_data': gate_old
    }

    msg_handler.send_message_to_exchange('gate', json.dumps(payload))

    return json.dumps(gate.to_dict())
def update(id):
    """
    Updates an existing check-in counter in the system
    ---
    parameters:
        -   in: path
            name: id
            required: true
            schema:
                type: number
                example: 1
            description: ID of the check-in counter
        -   in: body
            name: counter
            required: true
            schema:
                type: object
                properties:
                    number:
                        type: integer
                        description: Number of the check-in counter
                        example: 4
            description: The attributes of the check-in counter to update
    responses:
        200:
            description: Updated the check-in counter
            schema:
                $ref: "#/definitions/CheckInCounter"
        400:
            description: The given counter id is invalid

    """
    # Check if input is a number
    try:
        int(id)
    except ValueError:
        return 'Invalid id \"' + id + '\"', 400

    # Check if input number is smaller than 32 bit int
    if not abs(int(id)) <= 0xffffffff:
        return 'Invalid id \"' + id + '\"', 400

    # Check if check-in counter with given id exists
    if CheckInCounter.get(id=id) is None:
        return 'Check-in counter with id ' + id + ' does not exist', 400

    counter_update = json.loads(request.data.decode('UTF-8'))
    counter = CheckInCounter[id]
    counter_old = counter.to_dict(
    )  # Make dictionary of old counter object before updating it
    counter.update_props(counter_update)

    payload = {
        'id': str(uuid.uuid4()),
        'message': 'Check-in counter has been updated successfully',
        'from': 'check_in_counter_management',
        'type': 'PUT',
        'data': counter.to_dict(),
        'old_data': counter_old
    }

    msg_handler.send_message_to_exchange('check-in-counter',
                                         json.dumps(payload))

    return json.dumps(counter.to_dict())