| 1382 | } |
| 1383 | |
| 1384 | void DataStorageController::HandleGET_nodes_uid_children(const httplib::Request& req, httplib::Response& res) |
| 1385 | { |
| 1386 | if (!m_Bridge.HasDataStorage()) |
| 1387 | { |
| 1388 | this->SendErrorResponse(res, 503, ErrorResponse::DataStorageNotAvailable(req.path)); |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | const std::string parentUid = req.path_params.at("uid"); |
| 1393 | if (!ValidateUid(parentUid)) |
| 1394 | { |
| 1395 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest("Invalid UID format", req.path)); |
| 1396 | return; |
| 1397 | } |
| 1398 | |
| 1399 | // Check if parent node exists |
| 1400 | auto parentNode = m_Bridge.GetNode(parentUid); |
| 1401 | if (!parentNode.has_value()) |
| 1402 | { |
| 1403 | this->SendErrorResponse(res, 404, ErrorResponse::NodeNotFound(parentUid, req.path)); |
| 1404 | return; |
| 1405 | } |
| 1406 | |
| 1407 | // Parse query parameters and set parent filter |
| 1408 | NodeQueryParams params; |
| 1409 | try |
| 1410 | { |
| 1411 | params = this->ParseNodeQueryParams(req); |
| 1412 | } |
| 1413 | catch (const InvalidQueryParam& e) |
| 1414 | { |
| 1415 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(e.detail, req.path)); |
| 1416 | return; |
| 1417 | } |
| 1418 | params.parentUid = parentUid; |
| 1419 | |
| 1420 | // Use GetNodes with parent filter - eliminates need for separate GetChildren method |
| 1421 | auto queryResult = m_Bridge.GetNodes(params); |
| 1422 | |
| 1423 | int returnedCount = static_cast<int>(queryResult.nodes.size()); |
| 1424 | |
| 1425 | nlohmann::json response; |
| 1426 | response["data"] = queryResult.nodes; |
| 1427 | response["meta"]["parent_uid"] = parentUid; |
| 1428 | response["meta"]["total_count"] = queryResult.totalCount; |
| 1429 | response["meta"]["limit"] = queryResult.limit; |
| 1430 | response["meta"]["offset"] = queryResult.offset; |
| 1431 | response["meta"]["returned_count"] = returnedCount; |
| 1432 | |
| 1433 | // Echo the request's path filter back in meta as path_query (see "Path Query |
| 1434 | // Response" in the MITK REST API specification under Documentation/). |
| 1435 | if (params.path.has_value()) |
| 1436 | { |
| 1437 | response["meta"]["path_query"] = params.path.value(); |
| 1438 | } |
| 1439 | |
| 1440 | // Include pagination links if applicable |
| 1441 | auto links = BuildPaginationLinks(req, queryResult.limit, queryResult.offset, queryResult.totalCount, returnedCount); |