| 1780 | } |
| 1781 | |
| 1782 | void DataStorageController::HandleGET_nodes_uid_properties(const httplib::Request& req, httplib::Response& res) |
| 1783 | { |
| 1784 | if (!m_Bridge.HasDataStorage()) |
| 1785 | { |
| 1786 | this->SendErrorResponse(res, 503, ErrorResponse::DataStorageNotAvailable(req.path)); |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | const std::string uid = req.path_params.at("uid"); |
| 1791 | if (!ValidateUid(uid)) |
| 1792 | { |
| 1793 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest("Invalid UID format", req.path)); |
| 1794 | return; |
| 1795 | } |
| 1796 | |
| 1797 | // Parse property query parameters |
| 1798 | PropertyQueryParams params; |
| 1799 | try |
| 1800 | { |
| 1801 | params = this->ParsePropertyQueryParams(req); |
| 1802 | } |
| 1803 | catch (const InvalidQueryParam& e) |
| 1804 | { |
| 1805 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(e.detail, req.path)); |
| 1806 | return; |
| 1807 | } |
| 1808 | |
| 1809 | auto properties = m_Bridge.GetNodeProperties(uid, params); |
| 1810 | if (!properties.has_value()) |
| 1811 | { |
| 1812 | this->SendErrorResponse(res, 404, ErrorResponse::NodeNotFound(uid, req.path)); |
| 1813 | return; |
| 1814 | } |
| 1815 | |
| 1816 | // Get available contexts for this node |
| 1817 | auto availableContexts = m_Bridge.GetNodeAvailableContexts(uid); |
| 1818 | |
| 1819 | nlohmann::json response; |
| 1820 | response["data"]["properties"] = properties.value(); |
| 1821 | response["meta"]["count"] = properties.value().size(); |
| 1822 | |
| 1823 | // Report actual scope used (per API spec: "all", "node", "data") |
| 1824 | std::string scopeStr = "all"; |
| 1825 | if (params.scope == PropertyScope::Node) |
| 1826 | { |
| 1827 | scopeStr = "node"; |
| 1828 | } |
| 1829 | else if (params.scope == PropertyScope::Data) |
| 1830 | { |
| 1831 | scopeStr = "data"; |
| 1832 | } |
| 1833 | response["meta"]["property_scope"] = scopeStr; |
| 1834 | response["meta"]["context"] = params.context.has_value() ? nlohmann::json(params.context.value()) : nlohmann::json(nullptr); |
| 1835 | if (availableContexts.has_value()) |
| 1836 | { |
| 1837 | response["meta"]["available_contexts"] = availableContexts.value(); |
| 1838 | } |
| 1839 | |