| 2130 | } |
| 2131 | |
| 2132 | void RenderingController::HandlePUT_mxnSelectedPosition(const httplib::Request& req, httplib::Response& res) const |
| 2133 | { |
| 2134 | const auto id = ReadRequiredPathParam(req, "id"); |
| 2135 | |
| 2136 | if (!IsValidMxNWindowId(id)) |
| 2137 | { |
| 2138 | const auto error = ErrorResponse::InvalidRequest( |
| 2139 | "Malformed MxN window id '" + id + "'. Expected pattern: <prefix>__<bare> with URL-segment-safe characters.", |
| 2140 | req.path); |
| 2141 | this->SendErrorResponse(res, 400, error); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | if (req.body.empty()) |
| 2146 | { |
| 2147 | const auto error = ErrorResponse::InvalidRequest("Request body is required.", req.path); |
| 2148 | this->SendErrorResponse(res, 400, error); |
| 2149 | return; |
| 2150 | } |
| 2151 | |
| 2152 | nlohmann::json body; |
| 2153 | try |
| 2154 | { |
| 2155 | body = nlohmann::json::parse(req.body); |
| 2156 | } |
| 2157 | catch (const nlohmann::json::exception&) |
| 2158 | { |
| 2159 | const auto error = ErrorResponse::InvalidRequest("Invalid JSON body.", req.path); |
| 2160 | this->SendErrorResponse(res, 400, error); |
| 2161 | return; |
| 2162 | } |
| 2163 | |
| 2164 | Point3D newPos; |
| 2165 | if (const auto err = ParsePositionFromBody(body, newPos)) |
| 2166 | { |
| 2167 | const auto error = ErrorResponse::InvalidRequest(*err, req.path); |
| 2168 | this->SendErrorResponse(res, 400, error); |
| 2169 | return; |
| 2170 | } |
| 2171 | |
| 2172 | if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasMxNSelectedPositionSetter()) |
| 2173 | { |
| 2174 | const auto error = ErrorResponse::RenderWindowNotAvailable(req.path); |
| 2175 | this->SendErrorResponse(res, 503, error); |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | try |
| 2180 | { |
| 2181 | m_RenderWindowBridge->SetMxNSelectedPosition(id, newPos); |
| 2182 | res.status = 204; |
| 2183 | } |
| 2184 | catch (const mitk::Exception& e) |
| 2185 | { |
| 2186 | const auto error = ErrorResponse::RenderingError( |
| 2187 | std::string("Position update failed: ") + e.what(), req.path); |
| 2188 | this->SendErrorResponse(res, 422, error); |
| 2189 | } |