Browse Source

fix(api): include runner id in API responses

Runner::toJson() omitted the id, so GET /api/v1/runners and
/api/v1/runners/{id} returned runners with no identifier at all, leaving
API clients unable to address a runner they had just listed.

fromJson() already read the id back from _id, so the round trip was
asymmetric. Adds _id to toJson(), matching that and the shape every other
endpoint returns, and strips it in persistRunner() where the id is the
document key rather than a body field.
fszontagh 1 tháng trước cách đây
mục cha
commit
623e52a266
1 tập tin đã thay đổi với 7 bổ sung và 2 xóa
  1. 7 2
      src/webserver/runners/runner_registry.cpp

+ 7 - 2
src/webserver/runners/runner_registry.cpp

@@ -69,8 +69,11 @@ RunnerCapabilities RunnerCapabilities::fromJson(const nlohmann::json& j) {
 
 // Runner
 nlohmann::json Runner::toJson() const {
-    // Note: id is managed by database as _id
+    // _id mirrors the storage document key, matching fromJson() and the shape
+    // every other endpoint returns. persistRunner() strips it before writing,
+    // since there the id is the key rather than part of the body.
     return {
+        {"_id", id},
         {"address", address},
         {"status", runnerStatusToString(status)},
         {"registeredAt", registered_at},
@@ -307,7 +310,9 @@ void RunnerRegistry::checkRunnerTimeouts() {
 }
 
 void RunnerRegistry::persistRunner(const Runner& runner) {
-    storage_.update("runners", runner.id, runner.toJson(), 0, false);
+    nlohmann::json doc = runner.toJson();
+    doc.erase("_id");  // the id is the document key, not a body field
+    storage_.update("runners", runner.id, doc, 0, false);
 }
 
 void RunnerRegistry::removeRunner(const std::string& runner_id) {