1*77b36437SChicago Duan #pragma once 2*77b36437SChicago Duan 3*77b36437SChicago Duan #include "app.hpp" 4*77b36437SChicago Duan #include "query.hpp" 5*77b36437SChicago Duan #include "registries/privilege_registry.hpp" 6*77b36437SChicago Duan #include "utils/chassis_utils.hpp" 7*77b36437SChicago Duan 8*77b36437SChicago Duan #include <memory> 9*77b36437SChicago Duan #include <optional> 10*77b36437SChicago Duan #include <string> 11*77b36437SChicago Duan 12*77b36437SChicago Duan namespace redfish 13*77b36437SChicago Duan { 14*77b36437SChicago Duan 15*77b36437SChicago Duan inline void doPowerSubsystemCollection( 16*77b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 17*77b36437SChicago Duan const std::string& chassisId, 18*77b36437SChicago Duan const std::optional<std::string>& validChassisPath) 19*77b36437SChicago Duan { 20*77b36437SChicago Duan if (!validChassisPath) 21*77b36437SChicago Duan { 22*77b36437SChicago Duan BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId; 23*77b36437SChicago Duan messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 24*77b36437SChicago Duan return; 25*77b36437SChicago Duan } 26*77b36437SChicago Duan 27*77b36437SChicago Duan asyncResp->res.jsonValue["@odata.type"] = 28*77b36437SChicago Duan "#PowerSubsystem.v1_1_0.PowerSubsystem"; 29*77b36437SChicago Duan asyncResp->res.jsonValue["Name"] = "Power Subsystem"; 30*77b36437SChicago Duan asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; 31*77b36437SChicago Duan asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 32*77b36437SChicago Duan "redfish", "v1", "Chassis", chassisId, "PowerSubsystem"); 33*77b36437SChicago Duan asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 34*77b36437SChicago Duan asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 35*77b36437SChicago Duan 36*77b36437SChicago Duan asyncResp->res.addHeader( 37*77b36437SChicago Duan boost::beast::http::field::link, 38*77b36437SChicago Duan "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 39*77b36437SChicago Duan } 40*77b36437SChicago Duan 41*77b36437SChicago Duan inline void handlePowerSubsystemCollectionGet( 42*77b36437SChicago Duan App& app, const crow::Request& req, 43*77b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 44*77b36437SChicago Duan const std::string& chassisId) 45*77b36437SChicago Duan { 46*77b36437SChicago Duan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 47*77b36437SChicago Duan { 48*77b36437SChicago Duan return; 49*77b36437SChicago Duan } 50*77b36437SChicago Duan 51*77b36437SChicago Duan redfish::chassis_utils::getValidChassisPath( 52*77b36437SChicago Duan asyncResp, chassisId, 53*77b36437SChicago Duan std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId)); 54*77b36437SChicago Duan } 55*77b36437SChicago Duan 56*77b36437SChicago Duan inline void requestRoutesPowerSubsystem(App& app) 57*77b36437SChicago Duan { 58*77b36437SChicago Duan BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 59*77b36437SChicago Duan .privileges(redfish::privileges::getPowerSubsystem) 60*77b36437SChicago Duan .methods(boost::beast::http::verb::get)( 61*77b36437SChicago Duan std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); 62*77b36437SChicago Duan } 63*77b36437SChicago Duan 64*77b36437SChicago Duan } // namespace redfish 65