Exemple #1
0
def add_service_personal_info(request):
    if not (0 < len(request.servers_location) < 256):
        raise ValueError(
            "Personal info string should be between 0 and 256 symbols!")
    user_id, service = verify_token(request.token, request.user_type)
    add_service_servers_location(user_id, request.servers_location)
    return "Service {} location successfully updated!".format(service)
Exemple #2
0
def tickets_handler(request):
    user_id, username = verify_token(request.token, request.user_type)

    service_name = username
    create_ticket(service_name, request.ticket_code, request.ticket_content,
                  request.ticket_target_group)
    return "Ticket \"{}\" added to \"{}\" group".format(
        request.ticket_code, request.ticket_target_group)
Exemple #3
0
def get_tickets(request):
    user_id, username = verify_token(request.token, request.user_type)
    if config["debug"] \
            and config["debug_user_group"] in \
            get_user_groups_list_by_user_id(user_id):
        tickets_list = get_all_food_services_tickets()
    else:
        tickets_list = get_tickets_by_user_id(user_id)
    return {"count": len(tickets_list), "ticket_objects": tickets_list}
Exemple #4
0
def group_add(request):
    user_id, _ = verify_token(request.token, request.user_type)
    if config["debug"] \
       and request.target_group == config["debug_user_group"] \
       and request.group_invite == config["debug_user_group_invite_code"]:
        add_user_to_group(user_id, config["debug_user_group"])
        return "Sucessfully added to debug group!"
    activate_invite(user_id, request.target_group, request.group_invite)
    return "Sucessfully added to \"{}\" group"\
        .format(request.target_group)
Exemple #5
0
def get_food_service_ratings(json_data):
    if json_data.amount < 0 or json_data.offset < 0:
        raise ValueError("Amount and offset should not be negative!")
    user_id, _ = verify_token(json_data.token, json_data.user_type)
    servers_location = get_service_servers_location(user_id)
    ratings = get_ratings(user_id, json_data.stars, json_data.offset,
                          json_data.amount)
    return {
        "servers_location": servers_location,
        "count": len(ratings),
        "ratings": ratings
    }
Exemple #6
0
def get_services_ratings(request):
    if request.amount < 0 or request.offset < 0:
        raise ValueError("Amount and offset should not be negative!")
    verify_token(request.token, request.user_type)
    services_list = get_services_list(request.offset, request.amount)
    return {"count": len(services_list), "services": services_list}
Exemple #7
0
def rate_services(request):
    user_id, _ = verify_token(request.token, request.user_type)
    rate_service(request.service_name, user_id, request.stars, request.comment)
    return "Successfully rated {} with {} stars!".format(
        request.service_name, request.stars)
Exemple #8
0
def create_group(request):
    user_id, _ = verify_token(request.token, request.user_type)
    create_user_group(user_id, request.group)
    return "Group {} sucessfully created!".format(request.group)
Exemple #9
0
def create_invites(request):
    user_id, _ = verify_token(request.token, request.user_type)
    invite_codes = generate_invite_code(user_id, request.group,
                                        min(request.invites_amount, 6))
    return {"count": len(invite_codes), "invites": invite_codes}
Exemple #10
0
def check_cookie():
    cookie = request.cookies.get("token")
    if not cookie:
        raise ValueError()
    user_id, username = tokenizer.verify_token(cookie, "food_service")
    return user_id, username