Exemplo n.º 1
0
def remove_item():
    errors = validator.DeleteItem().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event = AppEngine.get_event_by_pin_code(request.json["pin_code"])
    try:
        event.remove_item(request.json["title"])
        return responses.response_200({"message": "deleted"})
    except ValueError as ex:
        return responses.response_invalid_request({"message": str(ex)})
Exemplo n.º 2
0
def login_to_app():
    username, password = check_credentials_exist(request)
    if not username:
        return responses.response_invalid_request(password)
    if AppEngine.is_logged_user(username, password):
        return responses.response_200(request.json)
    return responses.response_wrong_credentials()
Exemplo n.º 3
0
def add_item():
    errors = validator.Item().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event = AppEngine.get_event_by_pin_code(request.json["pin_code"])
    if not event:
        return responses.response_invalid_event()
    title = request.json['title']
    amount = request.json['amount']
    try:
        event.equipment_list.add_new_item(title, amount)
        return responses.response_200(
            json.loads(ItemEncoder().encode(
                event.get_equipment_list()[title])))
    except Exception as ex:
        return responses.response_invalid_request({"message": str(ex)})
Exemplo n.º 4
0
def add_item_in_charge():
    errors = validator.AddItemInCharge().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event = AppEngine.get_event_by_pin_code(request.json["pin_code"])
    if not event:
        return responses.response_invalid_event()
    title = request.json['title']
    in_charge = request.json['user_name']
    try:
        event.equipment_list.add_in_charge(title, in_charge)
        return responses.response_200(
            json.loads(ItemEncoder().encode(
                event.get_equipment_list()[title])))
    except Exception as ex:
        return responses.response_invalid_request({"message": str(ex)})
Exemplo n.º 5
0
def create_new_event():
    errors = validator.EventScheme().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    pin_code = AppEngine.create_new_event(request.json)
    event = AppEngine.get_event_by_pin_code(pin_code)
    return responses.response_200(event.get_event_info())
Exemplo n.º 6
0
def sign_up():
    username, password = check_credentials_exist(request)
    if not username:
        return responses.response_invalid_request(password)
    if AppEngine.signup_new_user(username, password):
        return responses.response_200(request.json)
    else:
        return responses.response_invalid_user_name()
Exemplo n.º 7
0
def set_item_price():
    errors = validator.SetItemPrice().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event = AppEngine.get_event_by_pin_code(request.json["pin_code"])
    if not event:
        return responses.response_invalid_event()
    title = request.json['title']
    price = request.json['price']
    who_paid = request.json['user_name']
    try:
        event.set_item_price(title, price, who_paid)
        return responses.response_200(
            json.loads(ItemEncoder().encode(
                event.get_equipment_list()[title])))
    except ValueError as ex:
        return responses.response_invalid_request({"message": str(ex)})
Exemplo n.º 8
0
def set_info():
    try:
        request_dict = validator.EventInfo().load(request.json)
        pin_code = request_dict["pin_code"]
        event = AppEngine.get_event_by_pin_code(pin_code)
        if not event:
            return responses.response_invalid_event()
        event.set_info(request_dict["info"])
        return responses.response_200(event.get_event_info())
    except ValidationError as errors:
        return responses.response_invalid_request(errors.messages)
Exemplo n.º 9
0
def set_kind_of_meal():
    try:
        request_dict = validator.KindOfMEalScheme().load(request.json)
        pin_code = request_dict["pin_code"]
        event = AppEngine.get_event_by_pin_code(pin_code)
        if not event:
            return responses.response_invalid_event()
        event.set_kind_of_meal(request_dict["kind_of_meal"])
        return responses.response_200(request_dict)
    except ValidationError as errors:
        return responses.response_invalid_request(errors.messages)
Exemplo n.º 10
0
def get_participant_events():
    app.app.logger.debug("In get_participant_events")
    app.app.logger.debug(f"Got request: {request} of type: {type(request)}")
    app.app.logger.debug(f"Got json: {request.json} ")
    user_email = request.json.get('userEmail', None)
    if not user_email:
        return responses.response_invalid_request(
            {"message": "UserEmail is required"})
    if user_email not in AppEngine.users_dict.keys():
        return responses.response_invalid_user_name()
    events_dict = AppEngine.get_user_events(user_email)
    return responses.response_200(events_dict)
Exemplo n.º 11
0
def add_message():
    try:
        request_dict = validator.MessageSchema().load(request.json)
        pin_code = request_dict["pin_code"]
        event = AppEngine.get_event_by_pin_code(pin_code)
        if not event:
            return responses.response_invalid_event()
        event.add_message(request_dict["title"], request_dict["text"],
                          request_dict["author"])
        return responses.response_200(request_dict)
    except ValidationError as errors:
        return responses.response_invalid_request(errors.messages)
Exemplo n.º 12
0
def add_ride():
    errors = validator.RideScheme().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event = AppEngine.get_event_by_pin_code(request.json["pin_code"])
    if not event:
        return responses.response_invalid_event()
    try:
        driver_user_name = request.json['driver_user_name']
        driver = event.participants_dict[driver_user_name]
        source = request.json['source']
        available_seats = request.json['available_seats']
        departure_time = request.json['departure_time']
        event.rides_board.add_ride(driver, available_seats, source, departure_time)
        return responses.response_200({"response": "added ride"})
    except KeyError:
        return responses.response_invalid_user_name()
Exemplo n.º 13
0
def add_new_participant():
    errors = validator.ParticipantScheme().validate(request.json)
    if errors:
        return responses.response_invalid_request(errors)
    event_pin_code = request.json["pin_code"]
    event = AppEngine.get_event_by_pin_code(event_pin_code)
    if not event:
        return responses.response_invalid_event()
    user_name = request.json['userEmail']
    meal_preference = request.json['mealPreference']
    glass_preference = request.json['glassPreference']
    chaser_preference = request.json['chaserPreference']
    allergies = request.json['allergies']
    if event.add_participant(user_name, meal_preference, allergies,
                             glass_preference, chaser_preference):
        return responses.response_200((event.get_event_info()))
    else:
        return responses.response_invalid_user_name()