Example #1
0
def delete_charge(id_):
    """API endpoint to remove a charge from the database
    """
    try:
        id_ = validate_id(id_)
        g.tx.charges.delete(id_)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success({})
Example #2
0
def get_charge(id_):
    """API endpoint to get a charge from the database
    """
    try:
        id_ = validate_id(id_)
        charge = g.tx.charges.get(id_)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success(charge)
Example #3
0
def delete_accommodation(id_):
    """Remove an accommodation from the database
    """
    try:
        id_ = validate_id(id_)
        g.tx.accommodations.delete(id_)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success({})
Example #4
0
def get_accommodation(id_):
    """Get an accommodation from the database
    """
    try:
        id_ = validate_id(id_)
        accommodation = g.tx.accommodations.get(id_)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success(accommodation)
Example #5
0
def update_charge(id_):
    """API endpoint to modify a charge's info in the database
    """
    charge = request.get_json(force=True, silent=True)

    try:
        charge['id'] = validate_id(id_)
        validate(charge, expect_id=True)
        g.tx.charges.udpate(charge)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success(charge)
Example #6
0
def update_accommodation(id_):
    """Update an accommodation in the database
    """
    accommodation = request.get_json(force=True, silent=True)
    if not accommodation:
        return make_error('No accommodation details provided')

    try:
        accommodation['id'] = validate_id(id_)
        validate(accommodation, expect_id=True)
        accommodation = g.tx.accommodations.update(accommodation)
    except utils.StoneretreatException as e:
        return make_error(str(e))

    return make_success(accommodation)
Example #7
0
def create_party():
    user_input = request.get_json()
    data = validate_json(request.get_json())
    _id = validate_id(user_input.get("id"))
    name = validate_empty_string(user_input.get("name"))
    hqAddress = validate_empty_string(user_input.get("hqAddress"))
    logoUrl = validate_empty_string(user_input.get("logoUrl"))
    exists = Party.party_does_not_exists(user_input.get("id"))
    valid_keys = [data, _id, name, logoUrl, hqAddress, exists]
    for key in valid_keys:
        if not key:
            response = custom_response(
                400, f"Invalid Input! check on data you are trying to submit")
            return response
    new_party = Party.save_party(user_input.get("id"), user_input.get("name"),
                                 user_input.get("hqAddress"),
                                 user_input.get("logoUrl"))
    return jsonify({
        "status": 201,
        "data": [{
            "id": new_party["id"],
            "name": new_party["name"]
        }]
    })
Example #8
0
def create_office():
    user_input = request.get_json()
    data = validate_json(request.get_json())
    _id = validate_id(user_input.get("id"))
    name = validate_empty_string(user_input.get("name"))
    _type = validate_empty_string(user_input.get("type"))
    exists = Office.office_does_not_exists(user_input.get("id"))
    valid_keys = [data, _id, name, _type, exists]
    for key in valid_keys:
        if not key:
            response = custom_response(
                400, f"Invalid Input! check on data you are trying to submit")
            return response
    new_office = Office.save_office(user_input.get("id"),
                                    user_input.get("name"),
                                    user_input.get("type"))
    return jsonify({
        "status":
        201,
        "data": [{
            "id": new_office["id"],
            "name": new_office["name"]
        }]
    })