| 1327 | } |
| 1328 | |
| 1329 | void DataStorageController::HandleDELETE_nodes_uid(const httplib::Request& req, httplib::Response& res) |
| 1330 | { |
| 1331 | if (!m_Bridge.HasDataStorage()) |
| 1332 | { |
| 1333 | this->SendErrorResponse(res, 503, ErrorResponse::DataStorageNotAvailable(req.path)); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | const std::string uid = req.path_params.at("uid"); |
| 1338 | if (!ValidateUid(uid)) |
| 1339 | { |
| 1340 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest("Invalid UID format", req.path)); |
| 1341 | return; |
| 1342 | } |
| 1343 | |
| 1344 | // Parse recursive parameter (default: false) |
| 1345 | bool recursive = false; |
| 1346 | if (req.has_param("recursive")) |
| 1347 | { |
| 1348 | std::string recursiveStr = req.get_param_value("recursive"); |
| 1349 | recursive = (recursiveStr == "true" || recursiveStr == "1"); |
| 1350 | } |
| 1351 | |
| 1352 | // Check if node exists first |
| 1353 | auto existingNode = m_Bridge.GetNode(uid); |
| 1354 | if (!existingNode.has_value()) |
| 1355 | { |
| 1356 | this->SendErrorResponse(res, 404, ErrorResponse::NodeNotFound(uid, req.path)); |
| 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | auto deleteResult = m_Bridge.DeleteNode(uid, recursive); |
| 1361 | |
| 1362 | if (!deleteResult.success) |
| 1363 | { |
| 1364 | // Check if failure was due to having children |
| 1365 | if (deleteResult.childrenCount > 0) |
| 1366 | { |
| 1367 | this->SendErrorResponse(res, 409, ErrorResponse::NodeHasChildren(deleteResult.childrenCount, req.path)); |
| 1368 | return; |
| 1369 | } |
| 1370 | this->SendErrorResponse(res, 500, ErrorResponse::InternalError("Failed to delete node", req.path)); |
| 1371 | return; |
| 1372 | } |
| 1373 | |
| 1374 | nlohmann::json response; |
| 1375 | response["data"]["deleted_uid"] = uid; |
| 1376 | if (!deleteResult.deletedChildren.empty()) |
| 1377 | { |
| 1378 | response["data"]["deleted_children"] = deleteResult.deletedChildren; |
| 1379 | } |
| 1380 | |
| 1381 | this->SendJsonResponse(res, 200, response); |
| 1382 | } |
| 1383 | |
| 1384 | void DataStorageController::HandleGET_nodes_uid_children(const httplib::Request& req, httplib::Response& res) |
| 1385 | { |