-
Notifications
You must be signed in to change notification settings - Fork 6
Misc fixes in the pivot functionallity #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added `VariablePlacementTests` class in `VariablePlacementTests.cs` to test `PlacementHandler`. - Introduced `PlacementHandler` class in `PlacementHandler.cs` implementing `IPlacementHandler`. - Added `IPlacementHandler` interface in `IPlacementHandler.cs`. - Updated `ModelStore.cs` with `CreateModelA` method for sample `PXModel`. - Added `CommaSeparatedStringToListOfStrings` model binder in `CommaSeparatedStringToListOfStrings.cs`. - Modified `TableApiController.cs` to: * Inject `IPlacementHandler` dependency. * Use `CommaSeparatedStringToListOfStrings` model binder for `heading` and `stub` query parameters. * Replace inline placement logic with `PlacementHandler`. - Added `IllegalPlacementSelection` method in `ProblemUtility.cs`. - Registered `IPlacementHandler` service in `Program.cs`.
In `PlacementHandler.cs`: - Changed method to find the first time variable from `FirstOrDefault` to `Find`. - Updated method to check if all variables are in the model from using `All` to `TrueForAll`. In `CommaSeparatedStringToListOfStrings.cs`: - Simplified retrieval of query keys by removing unnecessary list conversions. - Removed null key check and moved query value retrieval outside the null check. - Refactored splitting of query values into items for conciseness. - Extracted logic for cleaning and adding items to the result list into a new private method `CleanValue`. - `CleanValue` method now trims items and removes surrounding square brackets if present.
Encapsulated the logic for replacing the "TIME" constant with the actual time code into a new private static method `ReplaceTimeConstant`. This method improves code readability and maintainability by handling the replacement within a dedicated function. The original inline code has been removed and replaced with a call to this new method.
Extracted complex conditional checks into new methods `AllVariablesExistsInSelection` and `OnlyHeadOrStubIsSpecified` to improve readability and maintainability. Replaced inline conditions with method calls. Moved `ReplaceTimeConstant` method to accommodate new methods.
Reordered parameters in `Assert.AreEqual` calls in `VariablePlacementTests.cs` to place the expected value first and the actual value second. This change improves readability and consistency, aligning with common unit testing practices.
string? q = bindingContext.HttpContext.Request.Query[key]; | ||
if (q != null) | ||
{ | ||
var items = Regex.Split(q, ",(?=[^\\]]*(?:\\[|$))", RegexOptions.IgnoreCase, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add try catch around the timeout add log something clever :-)
? Why IgnoreCase :-) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can let code higher up in the chain catch the error. I Changed to ReqexOptions.None instead no need for case insensitivity.
{ | ||
return value.Substring(1, item2.Length - 2); | ||
} | ||
return item2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should "return value.Substring(1, item2.Length - 2);" also have a Trim() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I will add that
- Introduced BindModelAsync method to handle model binding asynchronously, with a check for null bindingContext. - Changed RegexOptions in Regex.Split from IgnoreCase to None for case-sensitive splitting. - Added a foreach loop to clean and process each item in the split query string. - Enhanced CleanValue method to trim leading and trailing whitespace from cleaned substrings.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
TableApiController.cs
to:IPlacementHandler
dependency.CommaSeparatedStringToListOfStrings
model binder forheading
andstub
query parameters.PlacementHandler
.VariablePlacementTests
class inVariablePlacementTests.cs
to testPlacementHandler
.PlacementHandler
class inPlacementHandler.cs
implementingIPlacementHandler
.IPlacementHandler
interface inIPlacementHandler.cs
.ModelStore.cs
withCreateModelA
method for samplePXModel
.CommaSeparatedStringToListOfStrings
model binder inCommaSeparatedStringToListOfStrings.cs
.IllegalPlacementSelection
method inProblemUtility.cs
.IPlacementHandler
service inProgram.cs
.