diff --git a/pkg/common/recursive_crud.go b/pkg/common/recursive_crud.go index a20ec6c..fb620b2 100644 --- a/pkg/common/recursive_crud.go +++ b/pkg/common/recursive_crud.go @@ -141,7 +141,7 @@ func (p *NestedCUDProcessor) ProcessNestedCUD( logger.Debug("Skipping insert for %s - no data columns besides _request", tableName) } - case "update": + case "update", "change": // Only perform update if we have data to update if hasData { rows, err := p.processUpdate(ctx, regularData, tableName, data[pkName]) diff --git a/pkg/restheadspec/empty_result_test.go b/pkg/restheadspec/empty_result_test.go index 25d21f6..802505e 100644 --- a/pkg/restheadspec/empty_result_test.go +++ b/pkg/restheadspec/empty_result_test.go @@ -14,23 +14,23 @@ func TestNormalizeResultArray_EmptyArrayWhenNoID(t *testing.T) { handler := &Handler{} tests := []struct { - name string - input interface{} + name string + input interface{} shouldBeEmptyObj bool }{ { - name: "nil should return empty object", - input: nil, + name: "nil should return empty object", + input: nil, shouldBeEmptyObj: true, }, { - name: "empty slice should return empty object", - input: []*EmptyTestModel{}, + name: "empty slice should return empty object", + input: []*EmptyTestModel{}, shouldBeEmptyObj: true, }, { - name: "single element should return the element", - input: []*EmptyTestModel{{ID: 1, Name: "test"}}, + name: "single element should return the element", + input: []*EmptyTestModel{{ID: 1, Name: "test"}}, shouldBeEmptyObj: false, }, { @@ -138,9 +138,9 @@ func TestSendResponseWithOptions_NoDataFoundHeader(t *testing.T) { t.Errorf("Expected X-No-Data-Found header to be 'true', got '%s'", mockWriter.headers["X-No-Data-Found"]) } - // Check status code is 204 when no records found - if mockWriter.statusCode != 204 { - t.Errorf("Expected status code 204, got %d", mockWriter.statusCode) + // Check status code is 200 even when no records found + if mockWriter.statusCode != 200 { + t.Errorf("Expected status code 200, got %d", mockWriter.statusCode) } // Verify the body is an empty array (list request, SingleRecordAsObject not set) diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index bfe603f..386f80a 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -2507,11 +2507,7 @@ func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interfac data = h.normalizeResultArray(data) } - if dataLen == 0 { - w.WriteHeader(http.StatusNoContent) - } else { - w.WriteHeader(http.StatusOK) - } + w.WriteHeader(http.StatusOK) if err := w.WriteJSON(data); err != nil { logger.Error("Failed to write JSON response: %v", err)