Пример #1
0
def auth_handler(http_receive, request):
    user = todo_user_load_from_decoded_data(
        http_request_get_decoded_data(request))

    if (user):
        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            print(user)

        response = http_response_json_msg(HTTP_STATUS_OK,
                                          "okay!".encode('utf-8'))

        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)

    else:
        response = http_response_json_error(HTTP_STATUS_BAD_REQUEST,
                                            "Bad user!".encode('utf-8'))

        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)
Пример #2
0
def todo_item_delete_handler(http_receive, request):
    user = controllers.users.todo_user_load_from_decoded_data(
        http_request_get_decoded_data(request))

    item_id_str = http_request_get_param_at_idx(request, 0)

    result = controllers.items.todo_item_delete_by_id_and_user(
        item_id_str, user)

    if (result):
        response = http_response_json_msg(HTTP_STATUS_OK,
                                          "Deleted item!".encode('utf-8'))

        if todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT:
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)

    else:
        response = http_response_json_error(HTTP_STATUS_NOT_FOUND,
                                            "Item not found".encode('utf-8'))

        if todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT:
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)
Пример #3
0
def users_handler(http_receive, request):
    response = http_response_json_msg(HTTP_STATUS_OK,
                                      "Users Works!".encode('utf-8'))

    if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
        http_response_print(response)

    http_response_send(response, http_receive)
    http_response_delete(response)
Пример #4
0
def todo_catch_all_handler(http_receive, request):
    response = http_response_json_msg(HTTP_STATUS_OK,
                                      "Todo Service!".encode('utf-8'))

    if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
        http_response_print(response)

    http_response_send(response, http_receive)
    http_response_delete(response)
Пример #5
0
def version_handler(http_receive, request):
    v = '%s - %s' % (version.TODO_VERSION_NAME, version.TODO_VERSION_DATE)

    response = http_response_json_key_value(HTTP_STATUS_OK,
                                            "version".encode('utf-8'),
                                            v.encode('utf-8'))

    if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
        http_response_print(response)

    http_response_send(response, http_receive)
    http_response_delete(response)
Пример #6
0
def users_register_handler(http_receive, request):
    body = http_request_get_body(request)

    result = controllers.users.todo_users_register(body)

    if (result == TODO_ERROR_NONE):
        response = http_response_json_msg(
            HTTP_STATUS_OK, "Created a new user!".encode('utf-8'))

        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)

    else:
        todo_error_send_response(result, http_receive)
Пример #7
0
def users_login_handler(http_receive, request):
    body = http_request_get_body(request)

    error, user = controllers.users.todo_users_login(body)

    if (error == TODO_ERROR_NONE):
        response = controllers.users.todo_user_generate_token(
            http_receive, user)
        http_response_compile(response)

        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)

    else:
        todo_error_send_response(error, http_receive)
Пример #8
0
def todo_item_create_handler(http_receive, request):
    user = controllers.users.todo_user_load_from_decoded_data(
        http_request_get_decoded_data(request))

    body = http_request_get_body(request)

    result = controllers.items.todo_item_create(user, body)

    if (result == TODO_ERROR_NONE):
        response = http_response_json_msg(
            HTTP_STATUS_OK, "Created a new item!".encode('utf-8'))

        if (todo.RUNTIME == runtime.RUNTIME_TYPE_DEVELOPMENT):
            http_response_print(response)

        http_response_send(response, http_receive)
        http_response_delete(response)

    else:
        todo_error_send_response(result, http_receive)