Example #1
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)
Example #2
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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #8
0
def todo_error_send_response (todo_error, http_receive):
	if (todo_error == TODO_ERROR_NONE):
		pass

	if (todo_error == TODO_ERROR_BAD_REQUEST):
		http_response_send (bad_request_error, http_receive)

	if (todo_error == TODO_ERROR_MISSING_VALUES):
		http_response_send (missing_values, http_receive)

	if (todo_error == TODO_ERROR_BAD_USER):
		http_response_send (bad_user_error, http_receive)

	if (todo_error == TODO_ERROR_EXISTING_USER):
		http_response_send (existing_user_error, http_receive)

	if (todo_error == TODO_ERROR_SERVER_ERROR):
		http_response_send (server_error, http_receive)
Example #9
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)