I am creating a dashboard. I obviously need to fetch some data. The problem is the data shown is based on user role.
- Administrator can see everything and columns that are fetched from database are x, y and z.
- Manager can see only rows for users that belongs to his region and columns that are fetched are only x and y.
- Employee can see only rows that belongs to him and only column x.
The narrowing is accidental. Admin as well might see one column and Manager ten.
So basically the number of rows and columns differ based on role.
I want to avoid single method in repository with a bunch of if statements. I would like to design this in a way that allows me to add roles in accordance with the SRP and OCP.
Maybe chain of responsibility is a good solution? I would create a bunch of Query objects with a method canHandle that would check user role?
This is my current solution: github