Giuseppe
Giuseppe
CC#
Created by Giuseppe on 5/30/2025 in #help
✅ Welp with making a function more abstract
I'm developing a website with server-side filtering. Users can save sets of filters, which are stored as JSON in a Filters table in the database. My challenge is that the filters can apply to different entities (e.g., Tasks, Bookings, Vehicles), so the input objects to the backend vary. My problem is with the functions that save and retrieve these filters: Saving: serialize the specific filter object to JSON and store it. Loading: read the JSON from the DB and deserialize it into the correct class. Since the only part where the code could change for saving/reading is the class used to deserialize and serialize, which could be the best approach to avoid code dup? I thought about using a template function. In this case would it be better to have different endpoints to save/retrieve data or could i pass the type of filter to the backend?
22 replies