microservicesdomain-driven-designcqrsn-tier-architecture

What layer has responsibility of filtering deactivated(mark as deleted) aggregate?


I read [this][1] (dont-delete-just-dont) article, and then I have agreed not to delete aggregate.

My question is that if I'm not using CQRS, what layer has the responsibility of filtering deactivated(mark as deleted) aggregate? It could be a use-case?

Does UI layers interface have parameters for the filter and do application layers show it explicitly on APIs? ​like this?

@RequestMapping(value = "/users/{userId}/articles", method = RequestMethod.GET)
    public ResponseEntity<String> getArticlesOfUser(
           ​@PathVariable long userId,
           ​@RequestParam(defaultValue = ture, required = false) boolean onlyActivated) {
        
       ​if(onlyActivated) {
          List<Article> articles = articleApplicationService.getAllActivatedArticlesOfUser(userId);
          return articlesResponse(articles);
       } else {
          List<Article> articles = articleApplicationService.getAllArticlesOfUser(userId);
          return articlesResponse(articles);
       }
    }

Or Should it be hidden in the persistence layer? like this?

public class JPAArticleRepository implements ArticleRepository {
 ​...
 ​public List<Article> allArticlesByUserId(long userId) {
   ​boolean activated = false
   ​String query = "select article from Article article 
                   ​where article.userId = :userId and article.activated= :activated";
   ​...
 ​}
 ​...
}

Any thoughts?

thanks

​[1]: https://udidahan.com/2009/09/01/dont-delete-just-dont


Solution

  • Modeling "soft deletes" as part of the business actions (instead of hiding it) is a good strategy so I recommend keeping that way and not hide it in persistence layer. Making querying part of the business concerns adds the right context to these queries and follows the mantra "Model the task, not the data" you can read in Udi post.

    Also; in general; hiding things usualy ends as pain in the ass for code maintenance, testing, training newcomers, etc. Another mantra I like to follow is "Always know what you are doing".