177b36437SChicago Duan #pragma once 277b36437SChicago Duan 377b36437SChicago Duan #include "app.hpp" 4*ca9e6be6SNan Zhou #include "logging.hpp" 577b36437SChicago Duan #include "query.hpp" 677b36437SChicago Duan #include "registries/privilege_registry.hpp" 777b36437SChicago Duan #include "utils/chassis_utils.hpp" 877b36437SChicago Duan 977b36437SChicago Duan #include <memory> 1077b36437SChicago Duan #include <optional> 1177b36437SChicago Duan #include <string> 1277b36437SChicago Duan 1377b36437SChicago Duan namespace redfish 1477b36437SChicago Duan { 1577b36437SChicago Duan 1677b36437SChicago Duan inline void doPowerSubsystemCollection( 1777b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1877b36437SChicago Duan const std::string& chassisId, 1977b36437SChicago Duan const std::optional<std::string>& validChassisPath) 2077b36437SChicago Duan { 2177b36437SChicago Duan if (!validChassisPath) 2277b36437SChicago Duan { 2377b36437SChicago Duan BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId; 2477b36437SChicago Duan messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 2577b36437SChicago Duan return; 2677b36437SChicago Duan } 2777b36437SChicago Duan 2877b36437SChicago Duan asyncResp->res.jsonValue["@odata.type"] = 2977b36437SChicago Duan "#PowerSubsystem.v1_1_0.PowerSubsystem"; 3077b36437SChicago Duan asyncResp->res.jsonValue["Name"] = "Power Subsystem"; 3177b36437SChicago Duan asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; 3277b36437SChicago Duan asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 3377b36437SChicago Duan "redfish", "v1", "Chassis", chassisId, "PowerSubsystem"); 3477b36437SChicago Duan asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 3577b36437SChicago Duan asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 3677b36437SChicago Duan 3777b36437SChicago Duan asyncResp->res.addHeader( 3877b36437SChicago Duan boost::beast::http::field::link, 3977b36437SChicago Duan "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 4077b36437SChicago Duan } 4177b36437SChicago Duan 4277b36437SChicago Duan inline void handlePowerSubsystemCollectionGet( 4377b36437SChicago Duan App& app, const crow::Request& req, 4477b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4577b36437SChicago Duan const std::string& chassisId) 4677b36437SChicago Duan { 4777b36437SChicago Duan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 4877b36437SChicago Duan { 4977b36437SChicago Duan return; 5077b36437SChicago Duan } 5177b36437SChicago Duan 5277b36437SChicago Duan redfish::chassis_utils::getValidChassisPath( 5377b36437SChicago Duan asyncResp, chassisId, 5477b36437SChicago Duan std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId)); 5577b36437SChicago Duan } 5677b36437SChicago Duan 5777b36437SChicago Duan inline void requestRoutesPowerSubsystem(App& app) 5877b36437SChicago Duan { 5977b36437SChicago Duan BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 6077b36437SChicago Duan .privileges(redfish::privileges::getPowerSubsystem) 6177b36437SChicago Duan .methods(boost::beast::http::verb::get)( 6277b36437SChicago Duan std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); 6377b36437SChicago Duan } 6477b36437SChicago Duan 6577b36437SChicago Duan } // namespace redfish 66