I'm building a REST API for which several users with different roles will have access to the resources it contains.
To keep the scope simple let's take the "student/teacher/class" domain:
GET /students is the resource to access.
Users might have roles like Student and/or Teacher
Students will only have access to students of their classes. Teachers will have access to students of the classes they teach. Some uses may be a student AND teach other classes too. They must have access to the students of their classes AND the students of the classes they teach.
Ideally I want to implement this as two functions - one per role and then "union" if a user have multiple roles.
My question is: Which pattern should I use for implementing this?
- Should I split up my API per role?
GET /student/studentsIt doesn't seems right to me.
- Keep it all I'm one resource (preferred)
How should it be implemented internally?
- Should every method start with a BIG switch/if per role?
- Should I implement a repository per role?
- Is there a design pattern that will help me in achieving this?
As a side comment: I'm using ASP.NET Web API and Entity Framework 6, but it really doesn't matter for the conceptual implementation.