Skip to content

Commit f4b4445

Browse files
authored
fix: Upgrade to the API specification 2.1.1 PXWEB-931 (#498)
* Changed `CodeList` to `Codelist` * Updated to latest version of the spec 2.1.1 * Avoid duplicate mapping in SavedQueryApiController Refactored the code to map the saved query response only once in the SavedQueryApiController. The mapped response is now reused for both extracting the URI and returning the Created() result, improving efficiency and code readability.
1 parent 864ade2 commit f4b4445

File tree

10 files changed

+30
-28
lines changed

10 files changed

+30
-28
lines changed

PxWeb.UnitTests/Helpers/SelectionUtilTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void VariablesSelectionFromCodelists_WhenOneCodelist_ReturnsSelectionWith
132132
Assert.IsNotNull(result);
133133
Assert.HasCount(1, result.Selection);
134134
Assert.AreEqual("A", result.Selection[0].VariableCode);
135-
Assert.AreEqual("B", result.Selection[0].CodeList);
135+
Assert.AreEqual("B", result.Selection[0].Codelist);
136136

137137
}
138138
}

PxWeb/Code/Api2/DataSelection/SelectionHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,18 @@ private static bool ApplyCodelist(IPXModelBuilder builder, Variable pxVariable,
260260
{
261261
problem = null;
262262

263-
if (!string.IsNullOrWhiteSpace(variable.CodeList))
263+
if (!string.IsNullOrWhiteSpace(variable.Codelist))
264264
{
265265
var notes = PaxiomFixUtil.ExtractNotes(pxVariable);
266266

267-
if (variable.CodeList.StartsWith("agg_"))
267+
if (variable.Codelist.StartsWith("agg_"))
268268
{
269269
if (!ApplyGrouping(builder, pxVariable, variable, out problem))
270270
{
271271
return false;
272272
}
273273
}
274-
else if (variable.CodeList.StartsWith("vs_"))
274+
else if (variable.Codelist.StartsWith("vs_"))
275275
{
276276
if (!ApplyValueset(builder, pxVariable, variable, out problem))
277277
{
@@ -298,13 +298,13 @@ private static bool ApplyGrouping(IPXModelBuilder builder, Variable pxVariable,
298298
{
299299
problem = null;
300300

301-
if (string.IsNullOrWhiteSpace(variable.CodeList))
301+
if (string.IsNullOrWhiteSpace(variable.Codelist))
302302
{
303303
problem = ProblemUtility.NonExistentCodelist();
304304
return false;
305305
}
306306

307-
GroupingInfo grpInfo = pxVariable.GetGroupingInfoById(variable.CodeList.Replace("agg_", ""));
307+
GroupingInfo grpInfo = pxVariable.GetGroupingInfoById(variable.Codelist.Replace("agg_", ""));
308308

309309
if (grpInfo is null)
310310
{
@@ -332,13 +332,13 @@ private static bool ApplyValueset(IPXModelBuilder builder, Variable pxVariable,
332332
{
333333
problem = null;
334334

335-
if (string.IsNullOrWhiteSpace(variable.CodeList))
335+
if (string.IsNullOrWhiteSpace(variable.Codelist))
336336
{
337337
problem = ProblemUtility.NonExistentCodelist();
338338
return false;
339339
}
340340

341-
ValueSetInfo vsInfo = pxVariable.GetValuesetById(variable.CodeList.Replace("vs_", ""));
341+
ValueSetInfo vsInfo = pxVariable.GetValuesetById(variable.Codelist.Replace("vs_", ""));
342342

343343
if (vsInfo is null)
344344
{

PxWeb/Controllers/Api2/SavedQueryApiController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public override IActionResult CreateSaveQuery([FromBody] SavedQuery? savedQuery)
8383

8484
// 3. Return the SavedQuery with the id set.
8585
savedQuery.Id = id;
86-
return Created(savedQuery.Id, savedQuery);
86+
var response = _savedQueryResponseMapper.Map(savedQuery);
87+
var uri = response.Links.FirstOrDefault(link => link.Rel == "self")?.Href ?? id;
88+
return Created(uri, response);
8789

8890
}
8991

PxWeb/Controllers/Api2/TablesApiController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private VariablesSelection MapDataParameters(Dictionary<string, List<string>>? v
304304
variableSelection.ValueCodes = valuecodes[variableCode];
305305
if (codelist != null && codelist.ContainsKey(variableCode))
306306
{
307-
variableSelection.CodeList = codelist[variableCode];
307+
variableSelection.Codelist = codelist[variableCode];
308308
}
309309
selections.Selection.Add(variableSelection);
310310
}

PxWeb/Helper/Api2/SelectionUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static VariablesSelection CreateVariablesSelectionFromCodelists(Dictionar
7474
{
7575
var selection = new VariableSelection();
7676
selection.VariableCode = key;
77-
selection.CodeList = codelist[key];
77+
selection.Codelist = codelist[key];
7878
selections.Selection.Add(selection);
7979
}
8080

@@ -157,7 +157,7 @@ public static VariablesSelection Copy(VariablesSelection selection)
157157
foreach (var variableSelection in selection.Selection)
158158
{
159159
var newVariableSelection = new VariableSelection();
160-
newVariableSelection.CodeList = variableSelection.CodeList;
160+
newVariableSelection.Codelist = variableSelection.Codelist;
161161
newVariableSelection.VariableCode = variableSelection.VariableCode;
162162
newVariableSelection.ValueCodes = new List<string>(variableSelection.ValueCodes);
163163
copy.Selection.Add(newVariableSelection);

PxWeb/Helper/Api2/VariablesSelectionExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static void AddStubVariable(this VariablesSelection selections, Variable
1111
var selection = new VariableSelection();
1212
selection.ValueCodes = new List<string>();
1313
selection.VariableCode = variable.Code;
14-
selection.CodeList = GetCodeList(variable);
14+
selection.Codelist = GetCodeList(variable);
1515
selection.ValueCodes.AddRange(valuesFunction(variable, numberOfValues));
1616
selections.Selection.Add(selection);
1717
selections.Placement?.Stub.Add(variable.Code);
@@ -22,7 +22,7 @@ public static void AddHeadingVariable(this VariablesSelection selections, Variab
2222
var selection = new VariableSelection();
2323
selection.ValueCodes = new List<string>();
2424
selection.VariableCode = variable.Code;
25-
selection.CodeList = GetCodeList(variable);
25+
selection.Codelist = GetCodeList(variable);
2626
selection.ValueCodes.AddRange(valuesFunction(variable, numberOfValues));
2727
selections.Selection.Add(selection);
2828
selections.Placement?.Heading.Add(variable.Code);
@@ -33,7 +33,7 @@ public static void AddVariableToHeading(this VariablesSelection selections, Vari
3333
var selection = new VariableSelection();
3434
selection.ValueCodes = new List<string>();
3535
selection.VariableCode = variable.Code;
36-
selection.CodeList = GetCodeList(variable);
36+
selection.Codelist = GetCodeList(variable);
3737
selection.ValueCodes.AddRange(valuesFunction(variable, 1));
3838
selections.Selection.Add(selection);
3939
selections.Placement?.Heading.Add(variable.Code);
@@ -44,7 +44,7 @@ public static void EliminateVariable(this VariablesSelection selections, Variabl
4444
var selection = new VariableSelection();
4545
selection.ValueCodes = new List<string>();
4646
selection.VariableCode = variable.Code;
47-
selection.CodeList = GetCodeList(variable);
47+
selection.Codelist = GetCodeList(variable);
4848
selections.Selection.Add(selection);
4949

5050
}

PxWeb/Models/Api2/DatasetSubclass.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ public static void AddCodelist(DimensionValue dimensionValue, List<CodelistInfor
482482
{
483483
dimensionValue.Extension = new ExtensionDimension();
484484
}
485-
if (dimensionValue.Extension.CodeLists == null)
485+
if (dimensionValue.Extension.Codelists == null)
486486
{
487-
dimensionValue.Extension.CodeLists = new List<CodelistInformation>();
487+
dimensionValue.Extension.Codelists = new List<CodelistInformation>();
488488
}
489-
dimensionValue.Extension.CodeLists.AddRange(codeLists);
489+
dimensionValue.Extension.Codelists.AddRange(codeLists);
490490
}
491491

492492
public static void AddMeasuringType(DimensionValue dimensionValue, string valueCode, MeasuringType measuringType)

PxWeb/PxWeb.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<PackageReference Include="PCAxis.Menu.ConfigDatamodelMenu" Version="1.0.10" />
5050
<PackageReference Include="PCAxis.Serializers" Version="1.9.3" />
5151
<PackageReference Include="PcAxis.Sql" Version="1.5.2" />
52-
<PackageReference Include="PxWeb.Api2.Server" Version="2.0.0" />
52+
<PackageReference Include="PxWeb.Api2.Server" Version="2.1.1" />
5353
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
5454
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.6" />
5555
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.6" />

PxWebApi_Mvc.Tests/ExpectedJson/MetadataById_tab003_js2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"extension": {
5858
"elimination": false,
5959
"show": "value",
60-
"codeLists": []
60+
"codelists": []
6161
}
6262
},
6363
"WASTE_CAT": {
@@ -139,7 +139,7 @@
139139
"extension": {
140140
"elimination": false,
141141
"show": "value",
142-
"codeLists": []
142+
"codelists": []
143143
}
144144
},
145145
"ContentsCode": {
@@ -167,7 +167,7 @@
167167
"extension": {
168168
"elimination": false,
169169
"show": "value",
170-
"codeLists": [],
170+
"codelists": [],
171171
"measuringType": {
172172
"WasteHazard": "Flow",
173173
"WasteNonHazard": "Average"
@@ -205,7 +205,7 @@
205205
"extension": {
206206
"elimination": false,
207207
"show": "code",
208-
"codeLists": []
208+
"codelists": []
209209
}
210210
}
211211
},

PxWebApi_Mvc.Tests/ExpectedJson/MetadataById_tab004_js2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"extension": {
7272
"elimination": false,
7373
"show": "value",
74-
"codeLists": []
74+
"codelists": []
7575
}
7676
},
7777
"GREENHOUSEGAS": {
@@ -112,7 +112,7 @@
112112
"extension": {
113113
"elimination": false,
114114
"show": "value",
115-
"codeLists": []
115+
"codelists": []
116116
}
117117
},
118118
"ContentsCode": {
@@ -134,7 +134,7 @@
134134
"extension": {
135135
"elimination": false,
136136
"show": "value",
137-
"codeLists": [],
137+
"codelists": [],
138138
"measuringType": {
139139
"Emission": "Stock"
140140
},
@@ -213,7 +213,7 @@
213213
"extension": {
214214
"elimination": false,
215215
"show": "code",
216-
"codeLists": []
216+
"codelists": []
217217
}
218218
}
219219
},

0 commit comments

Comments
 (0)