Skip to content
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

Add DateTime and numeric constructors to filters #119

Open
JanLenoch opened this issue Aug 15, 2018 · 0 comments · May be fixed by #384
Open

Add DateTime and numeric constructors to filters #119

JanLenoch opened this issue Aug 15, 2018 · 0 comments · May be fixed by #384
Labels
filters Stories related to queries and filters. good first issue groomed The issue has been groomed and should be in a good shape. hacktoberfest help wanted up-for-grabs

Comments

@JanLenoch
Copy link

JanLenoch commented Aug 15, 2018

Motivation

When using filters, the developer always specifies the element or attribute path (the predicate) and a value to filter by. The value has to be formatted specifically in order for the SDK to understand it.

Design guidelines

  • Create a generic Filter class that will accept T instead of string for the value parameter in its constructor
  • The Filter class will store Ts instead of strings in the Values property
  • Add DateTime and decimal constructors to all applicable filters.
  • The constructors will utilize the updated constructor of Filter that accepts objects as values
  • The GetQueryStringParameter() method of Filter will use pattern matching to distinguish between various types and will behave according to the specification:
    • format DateTime values to ISO-8601
    • format numeric types (int, float...) to "##########.##########"
    • treat all other types as strings and perform the current behavior

Example

    public string GetQueryStringParameter()
    {
        IEnumerable<string> values = Values switch
        {
            DateTime[] dates => values = dates.Select(d => d.ToString("o")),
            int[] numbers => numbers.Select(n => n.ToString()),
            _ => Values.Select(v => v.ToString())
        };

        var op = Uri.EscapeDataString(Operator ?? string.Empty);
        var element = Uri.EscapeDataString(ElementOrAttributePath);
        var escapedValues = string.Join(SEPARATOR, values.Select(Uri.EscapeDataString));
        return string.Format($"{element}{op}={escapedValues}");
    }

References

Pattern matching:

@JanLenoch JanLenoch changed the title Spike:Make Filters and Parameters less error-prone Spike: Make Filters and Parameters less error-prone Aug 15, 2018
@JanLenoch JanLenoch added help wanted up-for-grabs good first issue groomed The issue has been groomed and should be in a good shape. spike labels Aug 15, 2018
@petrsvihlik petrsvihlik removed the spike label Aug 5, 2019
@petrsvihlik petrsvihlik changed the title Spike: Make Filters and Parameters less error-prone Add DateTime and numeric constructors to filters Aug 5, 2019
@petrsvihlik petrsvihlik added the filters Stories related to queries and filters. label Jan 22, 2021
@nkooman nkooman linked a pull request Oct 17, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filters Stories related to queries and filters. good first issue groomed The issue has been groomed and should be in a good shape. hacktoberfest help wanted up-for-grabs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants