magento2-blog-module-tutorial icon indicating copy to clipboard operation
magento2-blog-module-tutorial copied to clipboard

Follow best practises around data models

Open ashsmith opened this issue 8 years ago • 0 comments

We should follow best practises set out by Magento by using data models to access our blog posts.

I'm going to implement the following

  • Ashsmith\Blog\Api\Data\PostInterface (this already exists)
  • Ashsmith\Blog\Api\PostRepositoryInterface
  • Ashsmith\Blog\Model\PostRepository
  • Ashsmith\Blog\Model\Data\Post

Then modify Ashsmith\Blog\Model\Post so that it no longer uses the interface, and has the method getDataModel.

PostRepositoryInterface should define the following methods:

  • getById($postId)
  • getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
  • delete(\Ashsmith\Blog\Api\Data\PostInterface $post)
  • deleteById($postId)

Any reference to loading the collections, or the original Post model directly will be switched out for the PostRepository.

ashsmith avatar Dec 04 '16 19:12 ashsmith