I’m working on a blog rest api and I would like to get some opinions on where to place the logic for a single operation to filter posts.
I have Category and Post in the model package. A category has a list of posts and a post has a single category.
The wrinkle is that posts can be hidden, meaning if you don’t have the correct permission you won’t see them. I’m using JPA and don’t want vendor specific SQL so I’m doing the filtering after retrieving the posts since I can’t join in the JPARepository.
Right now I have the helper method to filter a list of posts as package private in the PostController and the CategoryController autowires it in.
While that’s less than ideal I feel like having a PostService for this one method might be overkill and it should be in an object rather than a service.
Other options I considered were having it in the SecurityService (doesn’t really fit) or the Post model (it’s not part of the model so shouldn’t be here).
I also considered some design patterns but I don’t think anything really fits here ( decorator possibly but again seems like way too much )
This is a personal project so I’d really like to get it ‘right’. I can post code if required but I don’t think it really adds much to the discussion unless it’s hard for others to visualize