Skip to content

Commit

Permalink
Fix HTTP API: list databases
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
  • Loading branch information
JinHai-CN committed Mar 13, 2024
1 parent cbc865a commit 4dadb46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 2 additions & 7 deletions docs/http_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ create a new database.

#### Request
```http request
curl --request GET \
curl --request POST \
--url localhost:23820/databases/{database_name} \
--header 'accept: application/json' \
--header 'content-type: application/json' \
Expand Down Expand Up @@ -360,8 +360,6 @@ curl --request POST \
```

---


## Drop index

Drop index
Expand Down Expand Up @@ -392,8 +390,6 @@ curl --request DELETE \

---



## Insert

Insert data into table
Expand Down Expand Up @@ -516,7 +512,6 @@ curl --request PUT \

---


## Select

select data from table
Expand Down Expand Up @@ -583,7 +578,7 @@ Get variables
```http request
curl --request GET \
--url localhost:23820/variables/{variable_name} \
--header 'accept: application/json' \
--header 'accept: application/json'
```

#### Response
Expand Down
1 change: 1 addition & 0 deletions src/common/third_party.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@ export using HttpConnectionProvider = oatpp::network::tcp::server::ConnectionPro
export using WebServer = oatpp::network::Server;
export using WebEnvironment = oatpp::base::Environment;
export using WebAddress = oatpp::network::Address;
export using HTTPStatus = oatpp::web::protocol::http::Status;

} // namespace infinity
12 changes: 9 additions & 3 deletions src/network/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class ListDatabaseHandler final : public HttpRequestHandler {
DeferFn defer_fn([&]() { infinity->RemoteDisconnect(); });

auto result = infinity->ListDatabases();
nlohmann::json json_response;
HTTPStatus http_status;
if(result.IsOk()) {
nlohmann::json json_response;

SharedPtr<DataBlock> data_block = result.result_table_->GetDataBlockById(0);
auto row_count = data_block->row_count();
for (int i = 0; i < row_count; ++i) {
Expand All @@ -50,10 +52,14 @@ class ListDatabaseHandler final : public HttpRequestHandler {
json_response["databases"].push_back(db_name);
}

return ResponseFactory::createResponse(Status::CODE_200, json_response.dump());
json_response["error_code"] = 0;
http_status = HTTPStatus::CODE_200;
} else {
return ResponseFactory::createResponse(Status::CODE_404, "No database found");
json_response["error_code"] = result.ErrorCode();
json_response["error_message"] = result.ErrorMsg();
http_status = HTTPStatus::CODE_500;
}
return ResponseFactory::createResponse(HTTPStatus::CODE_500, json_response.dump());
}
};

Expand Down

0 comments on commit 4dadb46

Please sign in to comment.