coopTilleuls / workshop-apip-ddd

Demo project for the API Platform / DDD Workshop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workshop DDD x API Platform

This is a demo project used for the DDD x API Platform Workshop by @chalasr & @mtarld from @coopTilleuls.

Getting started

  1. Run git clone https://github.com/coopTilleuls/workshop-apip-ddd to clone the project
  2. Run make install to install the project
  3. Run make start to up your containers
  4. Visit https://localhost/api and play with your app!

Exercises

1. The domain layer

First, checkout the exercise tag: git checkout exercise1 -b exercise1

You can compare your code to the solution using git show exercise1-solved

1.1 - Adding a name
  • Let's create a App\BookStore\ValueObject\BookName value object
  • This BookName will have to hold a value (string)
  • That value length have to be less that 255
  • Now, create a rename method in Book to change the BookName
  • You'll have to update the DummyBookFactory to handle the name
  • Finally, update the BookTest::testRename to test your use case
1.2 - Applying a discount
  • Let's add a price to books
  • That price should always be greater than 0
  • The Book model must have a method that will apply a discount percentage on the price
  • You'll have to update the DummyBookFactory to handle the price creation
  • Finally, update the BookTest::testApplyDiscount to test your use case
1.3 - Integrating Doctrine
  • Let's add the proper ORM\Entity, ORM\Embedded, ORM\Embeddable and ORM\Column PHP attributes on value objects and models
  • Have a look at the DoctrineRepository class
  • Implement the missing methods in the DoctrineBookRepository
  • Finally, have a look at the DoctrineBookRepositoryTest and fill the missing test cases

2. The application layer

First, checkout the exercise tag: git checkout exercise2 -b exercise2

You can compare your code to the solution using git show exercise2-solved

2.1 - Finding a book
  • Let's create a App\BookStore\Application\Query\FindBookQuery query
  • That query will just hold the book id
  • Now let's update the associated handler so that it uses the query and the repository to retrieve a book by its id
  • Finally, update the FindBookTest to test functionally what you've just coded (using the query bus)
2.2 - Applying a discount
  • Let's create a DiscountBookCommand and its handler that will apply a discount on a specific book
  • Then, update the DiscountBookTest to test functionally what you've just coded (using the command bus)

3. The infrastructure layer (and API Platform!!)

First, checkout the exercise tag: git checkout exercise3 -b exercise3

You can compare your code to the solution using git show exercise3-solved

3.1 - Finding a book
  • Let's update the BookResource to specify the BookItemProvider in the Get operation
  • Fill in the BookItemProvider and dispatch the FindBookQuery to return (or not) a book based on the id
  • Update the FindBookTest acceptance test to really test the API
3.2 - Applying a discount
  • Let's update the BookResource to specify the proper provider and processor
  • You can now create the proper processor to apply a discount on a book (and return the updated book)
  • Update the DiscountBookTest acceptance test to really test the API

4. Bounded contexts

First, checkout the exercise tag: git checkout exercise4 -b exercise4

You can compare your code to the solution using git show exercise4-solved

4 - Handling subscriptions
  • Let's update the Subscription entity to make it as an API resource (with Post and Delete operations only)
  • Update API Platform's configuration to handle resources in the Subscription bounded context
  • Update the SubscriptionCrudTest acceptance test

Authors

Mathias Arlaud and Robin Chalas

About

Demo project for the API Platform / DDD Workshop

License:MIT License


Languages

Language:PHP 83.8%Language:Dockerfile 6.0%Language:Shell 4.6%Language:Makefile 4.6%Language:Twig 1.1%