I've created a database and included in the tables are these three relatives


I've created a data access API project, with simple methods for getting filtered results:


I've created a website which can call the API, and the aim is to have this API accessible on other places / websites too.

Then I start to get confused because of the possible options on where to put my filtering.

E.g. the website needs to present Games joined with GameHasPlayers. I'll create a new Model (or ViewModel?) called GamesAndPlayers and it'll show each game that contains a certain Player and also show each Player in that game.

  1. So on one hand, this feels like something that should go on outside of the data access and API layer because it's just a filter and join on existing Game and GameHasPlayer tables - I wouldn't want to bloat my API by adding filters and joins for any other similar cases. The onus is on the API caller / consumer to get data and do the sorting (e.g. website 1)

  2. On the other hand, I feel like my API can provide this quite well in one simple call, plus then it's available to all consumers (e.g. all websites that hook up to it) without code repetition, and it also prevents maintenance on a multitude of sites when changes occur.

So my question is - what other arguments for and against am I missing, and am I right to go with option 2?

| improve this question | | | | |

I would not create a seperate model for this as it is essentially just a query. It seems like you are using a framework and you may be able to find a good way to express what you are looking for in that framework's docs. They often have a solution when working in their idiom.

I am from rails land. We tend to try to limit our controller code to quick rejection of bad params and redirection.

If you are using rest then your endpoint is a resource and therefore a game is always just a game. Even if you decide to conditionally add players to that resource i would still call it the same.

I would probably create a query object that manages all of the filters.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.