Refactor LogService collection handler

The route handler for Systems LogService collection consisted of a huge
lambda. Extract the code and put it into a separate function.
Also, rename the route handler, to align with the Redfish resource
identifiers and reorder the placement of the functions, so that
requestRoutes functions are at the bottom of the file.

Tested: Code compiles.

Change-Id: Ifb9b27a5648870e5691777e7b031ff464a657b42
Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 3b7f8cf..3538f76 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -898,120 +898,108 @@
     }
 }
 
-inline void requestRoutesSystemLogServiceCollection(App& app)
+inline void handleSystemsLogServiceCollectionGet(
+    crow::App& app, const crow::Request& req,
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    const std::string& systemName)
 {
-    /**
-     * Functions triggers appropriate requests on DBus
-     */
-    BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
-        .privileges(redfish::privileges::getLogServiceCollection)
-        .methods(
-            boost::beast::http::verb::
-                get)([&app](const crow::Request& req,
-                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-                            const std::string& systemName) {
-            if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+    if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+    {
+        return;
+    }
+    if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
+    {
+        // Option currently returns no systems.  TBD
+        messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+                                   systemName);
+        return;
+    }
+    if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
+    {
+        messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+                                   systemName);
+        return;
+    }
+
+    // Collections don't include the static data added by SubRoute
+    // because it has a duplicate entry for members
+    asyncResp->res.jsonValue["@odata.type"] =
+        "#LogServiceCollection.LogServiceCollection";
+    asyncResp->res.jsonValue["@odata.id"] = std::format(
+        "/redfish/v1/Systems/{}/LogServices", BMCWEB_REDFISH_SYSTEM_URI_NAME);
+    asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
+    asyncResp->res.jsonValue["Description"] =
+        "Collection of LogServices for this Computer System";
+    nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
+    logServiceArray = nlohmann::json::array();
+    nlohmann::json::object_t eventLog;
+    eventLog["@odata.id"] =
+        std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
+                    BMCWEB_REDFISH_SYSTEM_URI_NAME);
+    logServiceArray.emplace_back(std::move(eventLog));
+    if constexpr (BMCWEB_REDFISH_DUMP_LOG)
+    {
+        nlohmann::json::object_t dumpLog;
+        dumpLog["@odata.id"] =
+            std::format("/redfish/v1/Systems/{}/LogServices/Dump",
+                        BMCWEB_REDFISH_SYSTEM_URI_NAME);
+        logServiceArray.emplace_back(std::move(dumpLog));
+    }
+
+    if constexpr (BMCWEB_REDFISH_CPU_LOG)
+    {
+        nlohmann::json::object_t crashdump;
+        crashdump["@odata.id"] =
+            std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
+                        BMCWEB_REDFISH_SYSTEM_URI_NAME);
+        logServiceArray.emplace_back(std::move(crashdump));
+    }
+
+    if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
+    {
+        nlohmann::json::object_t hostlogger;
+        hostlogger["@odata.id"] =
+            std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
+                        BMCWEB_REDFISH_SYSTEM_URI_NAME);
+        logServiceArray.emplace_back(std::move(hostlogger));
+    }
+    asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
+
+    constexpr std::array<std::string_view, 1> interfaces = {
+        "xyz.openbmc_project.State.Boot.PostCode"};
+    dbus::utility::getSubTreePaths(
+        "/", 0, interfaces,
+        [asyncResp](
+            const boost::system::error_code& ec,
+            const dbus::utility::MapperGetSubTreePathsResponse& subtreePath) {
+            if (ec)
             {
-                return;
-            }
-            if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
-            {
-                // Option currently returns no systems.  TBD
-                messages::resourceNotFound(asyncResp->res, "ComputerSystem",
-                                           systemName);
-                return;
-            }
-            if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
-            {
-                messages::resourceNotFound(asyncResp->res, "ComputerSystem",
-                                           systemName);
+                BMCWEB_LOG_ERROR("{}", ec);
                 return;
             }
 
-            // Collections don't include the static data added by SubRoute
-            // because it has a duplicate entry for members
-            asyncResp->res.jsonValue["@odata.type"] =
-                "#LogServiceCollection.LogServiceCollection";
-            asyncResp->res.jsonValue["@odata.id"] =
-                std::format("/redfish/v1/Systems/{}/LogServices",
-                            BMCWEB_REDFISH_SYSTEM_URI_NAME);
-            asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
-            asyncResp->res.jsonValue["Description"] =
-                "Collection of LogServices for this Computer System";
-            nlohmann::json& logServiceArray =
-                asyncResp->res.jsonValue["Members"];
-            logServiceArray = nlohmann::json::array();
-            nlohmann::json::object_t eventLog;
-            eventLog["@odata.id"] =
-                std::format("/redfish/v1/Systems/{}/LogServices/EventLog",
-                            BMCWEB_REDFISH_SYSTEM_URI_NAME);
-            logServiceArray.emplace_back(std::move(eventLog));
-            if constexpr (BMCWEB_REDFISH_DUMP_LOG)
+            for (const auto& pathStr : subtreePath)
             {
-                nlohmann::json::object_t dumpLog;
-                dumpLog["@odata.id"] =
-                    std::format("/redfish/v1/Systems/{}/LogServices/Dump",
-                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
-                logServiceArray.emplace_back(std::move(dumpLog));
+                if (pathStr.find("PostCode") != std::string::npos)
+                {
+                    nlohmann::json& logServiceArrayLocal =
+                        asyncResp->res.jsonValue["Members"];
+                    nlohmann::json::object_t member;
+                    member["@odata.id"] = std::format(
+                        "/redfish/v1/Systems/{}/LogServices/PostCodes",
+                        BMCWEB_REDFISH_SYSTEM_URI_NAME);
+
+                    logServiceArrayLocal.emplace_back(std::move(member));
+
+                    asyncResp->res.jsonValue["Members@odata.count"] =
+                        logServiceArrayLocal.size();
+                    return;
+                }
             }
-
-            if constexpr (BMCWEB_REDFISH_CPU_LOG)
-            {
-                nlohmann::json::object_t crashdump;
-                crashdump["@odata.id"] =
-                    std::format("/redfish/v1/Systems/{}/LogServices/Crashdump",
-                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
-                logServiceArray.emplace_back(std::move(crashdump));
-            }
-
-            if constexpr (BMCWEB_REDFISH_HOST_LOGGER)
-            {
-                nlohmann::json::object_t hostlogger;
-                hostlogger["@odata.id"] =
-                    std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
-                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
-                logServiceArray.emplace_back(std::move(hostlogger));
-            }
-            asyncResp->res.jsonValue["Members@odata.count"] =
-                logServiceArray.size();
-
-            constexpr std::array<std::string_view, 1> interfaces = {
-                "xyz.openbmc_project.State.Boot.PostCode"};
-            dbus::utility::getSubTreePaths(
-                "/", 0, interfaces,
-                [asyncResp](const boost::system::error_code& ec,
-                            const dbus::utility::MapperGetSubTreePathsResponse&
-                                subtreePath) {
-                    if (ec)
-                    {
-                        BMCWEB_LOG_ERROR("{}", ec);
-                        return;
-                    }
-
-                    for (const auto& pathStr : subtreePath)
-                    {
-                        if (pathStr.find("PostCode") != std::string::npos)
-                        {
-                            nlohmann::json& logServiceArrayLocal =
-                                asyncResp->res.jsonValue["Members"];
-                            nlohmann::json::object_t member;
-                            member["@odata.id"] = std::format(
-                                "/redfish/v1/Systems/{}/LogServices/PostCodes",
-                                BMCWEB_REDFISH_SYSTEM_URI_NAME);
-
-                            logServiceArrayLocal.emplace_back(
-                                std::move(member));
-
-                            asyncResp->res.jsonValue["Members@odata.count"] =
-                                logServiceArrayLocal.size();
-                            return;
-                        }
-                    }
-                });
         });
 }
 
-inline void handleBMCLogServicesCollectionGet(
+inline void handleManagersLogServicesCollectionGet(
     crow::App& app, const crow::Request& req,
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
     const std::string& managerId)
@@ -1062,7 +1050,7 @@
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR(
-                        "handleBMCLogServicesCollectionGet respHandler got error {}",
+                        "handleManagersLogServicesCollectionGet respHandler got error {}",
                         ec);
                     // Assume that getting an error simply means there are no
                     // dump LogServices. Return without adding any error
@@ -1124,14 +1112,6 @@
         asyncResp, eventlog_utils::LogServiceParent::Systems);
 }
 
-inline void requestRoutesBMCLogServiceCollection(App& app)
-{
-    BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
-        .privileges(redfish::privileges::getLogServiceCollection)
-        .methods(boost::beast::http::verb::get)(
-            std::bind_front(handleBMCLogServicesCollectionGet, std::ref(app)));
-}
-
 inline void getDumpServiceInfo(
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
     const std::string& dumpType)
@@ -2166,6 +2146,25 @@
             });
 }
 
+inline void requestRoutesSystemsLogServiceCollection(App& app)
+{
+    /**
+     * Functions triggers appropriate requests on DBus
+     */
+    BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/")
+        .privileges(redfish::privileges::getLogServiceCollection)
+        .methods(boost::beast::http::verb::get)(std::bind_front(
+            handleSystemsLogServiceCollectionGet, std::ref(app)));
+}
+
+inline void requestRoutesManagersLogServiceCollection(App& app)
+{
+    BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/LogServices/")
+        .privileges(redfish::privileges::getLogServiceCollection)
+        .methods(boost::beast::http::verb::get)(std::bind_front(
+            handleManagersLogServicesCollectionGet, std::ref(app)));
+}
+
 inline void requestRoutesSystemsEventLogService(App& app)
 {
     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/EventLog/")
diff --git a/redfish-core/src/redfish.cpp b/redfish-core/src/redfish.cpp
index 6f61f91..770e630 100644
--- a/redfish-core/src/redfish.cpp
+++ b/redfish-core/src/redfish.cpp
@@ -114,7 +114,7 @@
     requestRoutesCable(app);
     requestRoutesCableCollection(app);
 
-    requestRoutesSystemLogServiceCollection(app);
+    requestRoutesSystemsLogServiceCollection(app);
     requestRoutesSystemsEventLogService(app);
 
     requestRoutesSystemsLogServicesPostCode(app);
@@ -140,7 +140,7 @@
         requestRoutesFaultLogDumpClear(app);
     }
 
-    requestRoutesBMCLogServiceCollection(app);
+    requestRoutesManagersLogServiceCollection(app);
 
     if constexpr (BMCWEB_REDFISH_BMC_JOURNAL)
     {