| 354 | } |
| 355 | |
| 356 | void RenderingController::HandlePUT_selectedPosition(const httplib::Request& req, httplib::Response& res) const |
| 357 | { |
| 358 | if (req.body.empty()) |
| 359 | { |
| 360 | const auto error = ErrorResponse::InvalidRequest("Request body is required.", req.path); |
| 361 | this->SendErrorResponse(res, 400, error); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | nlohmann::json body; |
| 366 | try |
| 367 | { |
| 368 | body = nlohmann::json::parse(req.body); |
| 369 | } |
| 370 | catch (const nlohmann::json::exception&) |
| 371 | { |
| 372 | const auto error = ErrorResponse::InvalidRequest("Invalid JSON body.", req.path); |
| 373 | this->SendErrorResponse(res, 400, error); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | Point3D newPos; |
| 378 | if (const auto err = ParsePositionFromBody(body, newPos)) |
| 379 | { |
| 380 | const auto error = ErrorResponse::InvalidRequest(*err, req.path); |
| 381 | this->SendErrorResponse(res, 400, error); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasPositionSetter()) |
| 386 | { |
| 387 | const auto error = ErrorResponse::RenderWindowNotAvailable(req.path); |
| 388 | this->SendErrorResponse(res, 503, error); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | try |
| 393 | { |
| 394 | m_RenderWindowBridge->SetSelectedPosition(newPos); |
| 395 | res.status = 204; |
| 396 | } |
| 397 | catch (const RenderWindowBridgeNoEditorException& e) |
| 398 | { |
| 399 | const auto error = ErrorResponse::EditorNotActive(e.what(), req.path); |
| 400 | this->SendErrorResponse(res, 503, error); |
| 401 | } |
| 402 | catch (const std::exception& e) |
| 403 | { |
| 404 | const auto error = ErrorResponse::InternalError( |
| 405 | std::string("Failed to set crosshair position: ") + e.what(), req.path); |
| 406 | this->SendErrorResponse(res, 500, error); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | void RenderingController::HandleGET_selectedTime(const httplib::Request& req, httplib::Response& res) const |
| 411 | { |