samedi 7 août 2021

Need better design at forming c# object for an API rquest

I have json request that I need to send to an API which is of following format

  {
      "FilterName": "City",
      "Operator": "is", 
      "Values": ["city name"]
    },

I the above request the filtername can be City, state, street and for each there are a certain set of operators allowed for city : [is,contains], state:[is], streetNumber"[range,is,contains]

I want to create c# pattern for this where in I can

Create a class which force the use to the list of filters we provide and appropriate operators alond with it.

API provides 100 filter types but I need my application to allow only few of them .

forexample:

A request with state and city ( below request just my thought of how it should look like, it doenst have to be fluent )

Filterarray().AddFilter(StreetName().AddOperator("is)) // addoperator should allow is Filterarray().AddFilter(Cities().AddOperator("is/contans)) // addoperator should allow is / contains

Currently Im sending hardcoded values lie new Filter("state","is","value"). I dont want to do this, I need to learn something more refine. Please let me know your suggestions for a better way to add each filter and maintainable pattern

Aucun commentaire:

Enregistrer un commentaire