Skip to content

Commit ab85b89

Browse files
Fix/sq create failure not 201 (#473)
* Update SavedQueryDatabaseStorageBackend.cs Letting exception propagate * Update SavedQueryApiController.cs Check problem is not null (out problem was not used/checked/read ) * Update SavedQueryDatabaseStorageBackendTests.cs chaged test to expect an exception
1 parent af9bce7 commit ab85b89

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

PxWeb.UnitTests/SavedQuery/SavedQueryDatabaseStorageBackendTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void UpdatedStatistics_ShouldReturnFalse_WhenInvalidId()
193193
}
194194

195195
[TestMethod]
196-
public void Save_ShouldReturnEmptyString_WhenNoConnectionStringSpecified()
196+
public void Save_ShouldThrowException_WhenNoConnectionStringSpecified()
197197
{
198198
// Arrange
199199
var options = new SavedQueryDatabaseStorageOptions
@@ -219,10 +219,7 @@ public void Save_ShouldReturnEmptyString_WhenNoConnectionStringSpecified()
219219
var backend = new SavedQueryDatabaseStorageBackend(mockDataSourceOptions.Object, mockStorageOptions.Object, resolver.Object);
220220

221221
// Act
222-
var result = backend.Save("", "0", "sv");
223-
224-
// Assert
225-
Assert.AreEqual(string.Empty, result);
222+
Assert.Throws<Exception>(() => backend.Save("", "0", "sv"));
226223

227224
}
228225

PxWeb/Code/Api2/SavedQueryBackend/DatabaseBackend/SavedQueryDatabaseStorageBackend.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,10 @@ public string Save(string savedQuery, string tableId, string language)
5353
var mainTable = _tablePathResolver.Resolve(language, tableId, out exists);
5454
if (!exists)
5555
{
56-
mainTable = "?";
56+
mainTable = "?"; //better to throw something isnt it?
5757
}
5858

59-
try
60-
{
61-
return _savedQueryDatabaseAccessor.Save(savedQuery, mainTable, null).ToString();
62-
}
63-
catch (Exception ex)
64-
{
65-
// Log the error (not implemented in this example)
66-
Debug.WriteLine($"Error saving query: {ex.Message}");
67-
}
68-
return string.Empty;
69-
59+
return _savedQueryDatabaseAccessor.Save(savedQuery, mainTable, null).ToString();
7060
}
7161

7262
public bool UpdateRunStatistics(string id)

PxWeb/Controllers/Api2/SavedQueryApiController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public override IActionResult CreateSaveQuery([FromBody] SavedQuery? savedQuery)
6262

6363
_dataWorkflow.Run(savedQuery.TableId, savedQuery.Language, variablesSelection, out problem);
6464

65+
if (problem is not null)
66+
{
67+
return BadRequest(problem);
68+
}
69+
6570
string id;
6671
try
6772
{

0 commit comments

Comments
 (0)