| 907 | } |
| 908 | |
| 909 | void DataStorageController::HandleGET_nodes(const httplib::Request& req, httplib::Response& res) |
| 910 | { |
| 911 | if (!m_Bridge.HasDataStorage()) |
| 912 | { |
| 913 | this->SendErrorResponse(res, 503, ErrorResponse::DataStorageNotAvailable(req.path)); |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | // Parse query parameters |
| 918 | NodeQueryParams params; |
| 919 | try |
| 920 | { |
| 921 | params = this->ParseNodeQueryParams(req); |
| 922 | } |
| 923 | catch (const InvalidQueryParam& e) |
| 924 | { |
| 925 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(e.detail, req.path)); |
| 926 | return; |
| 927 | } |
| 928 | |
| 929 | auto queryResult = m_Bridge.GetNodes(params); |
| 930 | |
| 931 | int returnedCount = static_cast<int>(queryResult.nodes.size()); |
| 932 | |
| 933 | nlohmann::json response; |
| 934 | response["data"] = queryResult.nodes; |
| 935 | response["meta"]["total_count"] = queryResult.totalCount; |
| 936 | response["meta"]["limit"] = queryResult.limit; |
| 937 | response["meta"]["offset"] = queryResult.offset; |
| 938 | response["meta"]["returned_count"] = returnedCount; |
| 939 | |
| 940 | // Include pagination links if applicable |
| 941 | auto links = BuildPaginationLinks(req, queryResult.limit, queryResult.offset, queryResult.totalCount, returnedCount); |
| 942 | if (!links.empty()) |
| 943 | { |
| 944 | response["meta"]["links"] = links; |
| 945 | } |
| 946 | |
| 947 | // Include query info: context, filters, sorting, field limitations |
| 948 | response["meta"]["context"] = params.context.has_value() ? nlohmann::json(params.context.value()) : nlohmann::json(nullptr); |
| 949 | |
| 950 | // Property scope |
| 951 | std::string scopeStr = "all"; |
| 952 | if (params.propertyScope == PropertyScope::Node) |
| 953 | { |
| 954 | scopeStr = "node"; |
| 955 | } |
| 956 | else if (params.propertyScope == PropertyScope::Data) |
| 957 | { |
| 958 | scopeStr = "data"; |
| 959 | } |
| 960 | response["meta"]["property_scope"] = scopeStr; |
| 961 | |
| 962 | // Echo the request's path filter back in meta as path_query (see "Path Query |
| 963 | // Response" in the MITK REST API specification under Documentation/). |
| 964 | if (params.path.has_value()) |
| 965 | { |
| 966 | response["meta"]["path_query"] = params.path.value(); |