-
Notifications
You must be signed in to change notification settings - Fork 2
Issue #110: update book tutorial #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: horea <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be continued...
Signed-off-by: horea <[email protected]>
Signed-off-by: horea <[email protected]>
Signed-off-by: horea <[email protected]>
Signed-off-by: horea <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
In
ReleaseDateInput
, replace:
'message' => sprintf(Message::INVALID_VALUE, 'releaseDate'),
with:
'message' => Message::INVALID_VALUE,
and removeuse function sprintf;
. -
The migrations diff command is outdated, replace it with:
php ./vendor/bin/doctrine-migrations diff
- The path mentioned in this sentence has changed in
6.0
:
This will check for differences between your entities and database structure and create migration files if necessary, in
data/doctrine/migrations
.
Version 6.0
stores migrations in the Core module under the following path:
src/Core/src/App/src/Migration
- The migrations run command should also be updated:
php ./vendor/bin/doctrine-migrations migrate
-
Rename across the document
GetBookHandler
toGetBookResourceHandler
-
Rename across the document
PostBookHandler
toPostBookResourceHandler
so that they follow our naming convention.
Signed-off-by: horea <[email protected]>
Signed-off-by: horea <[email protected]>
Signed-off-by: horea <[email protected]>
]; | ||
} | ||
$routeCollector->post('/book', PostBookHandler::class, 'book::create-book'); | ||
$routeCollector->get('/book/' . $uuid, GetBookHandler::class, 'book::view-book'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$routeCollector->get('/book/' . $uuid, GetBookHandler::class, 'book::view-book'); | |
$routeCollector->get('/book/' . $uuid, GetBookResourceHandler::class, 'book::view-book'); |
Because:
Rename across the document
GetBookHandler
toGetBookResourceHandler
], | ||
]; | ||
} | ||
$routeCollector->post('/book', PostBookHandler::class, 'book::create-book'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$routeCollector->post('/book', PostBookHandler::class, 'book::create-book'); | |
$routeCollector->post('/book', PostBookResourceHandler::class, 'book::create-book'); |
Because:
Rename across the document
PostBookHandler
toPostBookResourceHandler
│ └── src/ | ||
│ ├── Collection/ | ||
│ │ └── BookCollection.php | ||
│ ├── Entity/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove node - the Book
entity is in the Core
module.
> Make sure you read and understand the rbac documentation. | ||
|
||
It's time to update the `ConfigProvider` with all the necessary configuration needed, so the above files to work properly like dependency injection, aliases, doctrine mapping and so on. | ||
After we have the handler, we need to register some routes in the `RoutesDelegator` using our new grouping method, the same we created when we registered the module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we have the handler, we need to register some routes in the `RoutesDelegator` using our new grouping method, the same we created when we registered the module. | |
After we have the handler, we need to register some routes in the `RoutesDelegator`, the same we created when we registered the module. |
We abandoned route groups for this tutorial.
|
||
In `src/Book/src` we will create 2 php files: `RoutesDelegator.php` and `ConfigProvider.php`. This files will be updated later with all needed configuration. | ||
In `src/Book/src` we will create 2 PHP files: `RoutesDelegator.php` and `ConfigProvider.php`. These files contain the necessary configurations. | ||
|
||
* `src/Book/src/RoutesDelegator.php` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is duplicate - you are creating the RoutesDelegator
towards the end of the tutorial.
Let's keep only that one!
* `src/Book/src/Service/BookService.php` – is a class or component responsible for performing a specific task or providing functionality to other parts of the application | ||
* `src/Core/src/Book/src/ConfigProvider.php` – is a class that provides configuration for Doctrine ORM | ||
* `src/Core/src/Book/src/Entity/Book.php` – an entity refers to a PHP class that represents a persistent object or data structure | ||
* `src/Core/src/Book/src/Repository/BookRepository.php` – a repository is a class responsible for querying and retrieving entities from the database | ||
|
||
## Creating and configuring the module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section could be a bit confusing for devs.
You instruct them to create a ConfigProvider
with classes which don't exist yet - better leave it for when all the classes have been created.
We should keep here only the instructions for creating the directory structure and move the creation of the two ConfigProvider
s and the RouteDelegator
to the end of the File creation and contents
section.
], | ||
], | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
### Registering the module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should also be moved further down to the point where the ConfigProvider
has already been created.
|
||
To keep things simple in this tutorial our book will have 3 properties: `name`, `author` and `release date`. | ||
To keep things simple in this tutorial, our book will have 3 properties: `name`, `author` and `release date`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep things simple in this tutorial, our book will have 3 properties: `name`, `author` and `release date`. | |
To keep things simple in this tutorial, our book will have 3 properties: `name`, `author` and `releaseDate`. |
@@ -460,29 +555,29 @@ class ReleaseDateInput extends Input | |||
|
|||
$this->getValidatorChain() | |||
->attachByName(Date::class, [ | |||
'message' => sprintf(Message::INVALID_VALUE, 'releaseDate'), | |||
'message' => Message::INVALID_VALUE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'message' => Message::INVALID_VALUE, | |
'message' => Message::invalidValue('releaseDate'), |
Signed-off-by: horea <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this, these steps will have to be tested in version 6.0
of Dotkernel API.
namespace Api\Book; | ||
|
||
use Api\Book\Handler\BookHandler; | ||
use Api\Book\Handler\GetBookCollectionHandler; | ||
use Api\Book\Handler\GetBookHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Api\Book\Handler\GetBookHandler; | |
use Api\Book\Handler\GetBookResourceHandler; |
|
||
## File creation and contents | ||
|
||
In `src` and `src/Core/src` folders we will create one `Book` folder and in those we will create the `src` folder. | ||
So the final structure will be like this: `src/Book/src` and `src/Core/src/Book/src`. | ||
|
||
Each file below have a summary description above of what that file does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each file below have a summary description above of what that file does. |
Devs just read through these descriptions, no need to do it again.
@@ -248,26 +165,22 @@ class Book extends AbstractEntity | |||
|
|||
``` | |||
|
|||
* `src/Book/src/Repository/BookRepository.php` | |||
* `src/Core/src/Book/src/Repository/BookRepository.php` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repository structure in general has changed in 6.0
.
Having a saveBook
method is correct, but note that there is a generic saveResource
method.
getBooks
should not return a Query
instance, but a QueryBuilder
, see example here.
use DateTimeImmutable; | ||
use Dot\DependencyInjection\Attribute\Inject; | ||
use Exception; | ||
|
||
class BookService implements BookServiceInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some refactoring, see AdminService in 6.0
for example.
Then adapt BookServiceInterface
.
``` | ||
|
||
That's it. The module is now registered. | ||
|
||
We need to configure access to the newly created endpoints, add `books::list-books`, `book::view-book` and `book::create-book` to the authorization rbac array, under the `UserRole::ROLE_GUEST` key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to configure access to the newly created endpoints, add `books::list-books`, `book::view-book` and `book::create-book` to the authorization rbac array, under the `UserRole::ROLE_GUEST` key. | |
We need to configure access to the newly created endpoints. | |
Open `config/autoload/authorization.global.php` and append the below route names to the `UserRoleEnum::Guest->value` key: | |
- `books::list-books` | |
- `book::view-book` | |
- `book::create-book` |
|
||
We need to configure access to the newly created endpoints, add `books::list-books`, `book::view-book` and `book::create-book` to the authorization rbac array, under the `UserRole::ROLE_GUEST` key. | ||
> Make sure you read and understand the rbac [documentation](https://docs.dotkernel.org/dot-rbac-guard/v4/configuration/). | ||
|
||
## Migrations | ||
|
||
We created the `Book` entity, but we didn't create the associated table for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this section:
- fix typo
shel
- replace
php bin/doctrine orm:validate-schema
withphp ./bin/doctrine orm:validate-schema
Signed-off-by: horea <[email protected]>
No description provided.