| 108 | } |
| 109 | |
| 110 | void RenderingController::HandlePOST_update(const httplib::Request& req, httplib::Response& res) const |
| 111 | { |
| 112 | auto type = RenderingManager::REQUEST_UPDATE_ALL; |
| 113 | |
| 114 | if (!req.body.empty()) |
| 115 | { |
| 116 | try |
| 117 | { |
| 118 | const auto body = nlohmann::json::parse(req.body); |
| 119 | if (body.contains("type")) |
| 120 | { |
| 121 | const auto typeStr = body["type"].get<std::string>(); |
| 122 | if (typeStr == "all") |
| 123 | { |
| 124 | type = RenderingManager::REQUEST_UPDATE_ALL; |
| 125 | } |
| 126 | else if (typeStr == "2d") |
| 127 | { |
| 128 | type = RenderingManager::REQUEST_UPDATE_2DWINDOWS; |
| 129 | } |
| 130 | else if (typeStr == "3d") |
| 131 | { |
| 132 | type = RenderingManager::REQUEST_UPDATE_3DWINDOWS; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | const auto error = ErrorResponse::InvalidRequest( |
| 137 | "Invalid type '" + typeStr + "'. Must be 'all', '2d', or '3d'.", req.path); |
| 138 | this->SendErrorResponse(res, 400, error); |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | catch (const nlohmann::json::exception&) |
| 144 | { |
| 145 | const auto error = ErrorResponse::InvalidRequest("Invalid JSON body.", req.path); |
| 146 | this->SendErrorResponse(res, 400, error); |
| 147 | return; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | try |
| 152 | { |
| 153 | this->Dispatch([type]() { |
| 154 | RenderingManager::GetInstance()->RequestUpdateAll(type); |
| 155 | }); |
| 156 | res.status = 204; |
| 157 | } |
| 158 | catch (const mitk::Exception& e) |
| 159 | { |
| 160 | const auto error = ErrorResponse::RenderingError( |
| 161 | std::string("Rendering operation failed: ") + e.what(), req.path); |
| 162 | this->SendErrorResponse(res, 422, error); |
| 163 | } |
| 164 | catch (const std::exception& e) |
| 165 | { |
| 166 | const auto error = ErrorResponse::InternalError( |
| 167 | std::string("Unexpected error during rendering: ") + e.what(), req.path); |