I need to modify an existing search API. The search API accepts SearchCriteria as request body to filter out the records. I need to add another filter to this SearchCriteria. The filter will take a list of IDs and return resources that has the IDs given.
Table: Employee
| ID | departmentId ||------|--------------|| 1001 | 1 || 1001 | 2 || 1001 | 3 || 1001 | NULL |
Here lets say the request will look like
{"searchCriteria": {"departmentId": ["1","2","3"] }}
The result should return all the resources that matches the department Id. This is straight forward.
But how to retrive the employees that have departmentId as NULL as shown in the table.The challenges are
- The api consumer can skip the field itself in the request. In this case, all the employees should be returned.
- The request could have this field as null. In this case also, all the employees should be sent in the response
- The request has empty list. This should also be treated as above.
- The request has list with "null". Then the response should have the employees that have departmentId as null. Note the consumer tech stack will be different, in case of Python, it would be "None", in case of JavaScript it would be "undefined".
How to handle this? What is the best practice?