You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public function getBooks(array $params): QueryBuilder;
216
218
}
219
+
217
220
```
218
221
219
222
*`src/Book/src/Service/BookService.php`
@@ -283,6 +286,7 @@ class BookService implements BookServiceInterface
283
286
return $this->bookRepository->getBooks($params);
284
287
}
285
288
}
289
+
286
290
```
287
291
288
292
When creating or updating a book, we will need some validators, so we will create input filters that will be used to validate the data received in the request
@@ -320,6 +324,7 @@ class AuthorInput extends Input
class CreateBookInputFilter extends AbstractInputFilter
412
419
{
@@ -417,6 +424,7 @@ class CreateBookInputFilter extends AbstractInputFilter
417
424
$this->add(new ReleaseDateInput('releaseDate'));
418
425
}
419
426
}
427
+
420
428
```
421
429
422
430
We create separate `Input` files to demonstrate their reusability and obtain a clean `CreateBookInputFilter` but you could have all the inputs created directly in the `CreateBookInputFilter` like this:
@@ -501,13 +509,16 @@ class GetBookCollectionHandler extends AbstractHandler
In `src/Book/src` we now create the 2 PHP files: `RoutesDelegator.php` and `ConfigProvider.php`.
@@ -643,6 +658,7 @@ class ConfigProvider
643
658
];
644
659
}
645
660
}
661
+
646
662
```
647
663
648
664
*`src/Book/src/RoutesDelegator.php`
@@ -684,6 +700,7 @@ class RoutesDelegator
684
700
return $callback();
685
701
}
686
702
}
703
+
687
704
```
688
705
689
706
In `src/Core/src/Book/src` we will create `ConfigProvider.php` where we configure Doctrine ORM.
@@ -738,12 +755,13 @@ class ConfigProvider
738
755
];
739
756
}
740
757
}
758
+
741
759
```
742
760
743
761
### Registering the module
744
762
745
-
* register the module config by adding `Api\Book\ConfigProvider::class` and `Core\Book\ConfigProvider::class` in `config/config.php` under the `Api\User\ConfigProvider::class`
746
-
* register the namespace by adding this line `"Api\\Book\\": "src/Book/src/"` and `"Core\\Book\\": "src/Core/src/Book/src/"`, in composer.json under the autoload.psr-4 key
763
+
* register the module config by adding `Api\Book\ConfigProvider::class,` and `Core\Book\ConfigProvider::class,` in `config/config.php` under the `Api\User\ConfigProvider::class,`
764
+
* register the namespace by adding this line `"Api\\Book\\": "src/Book/src/"` and `"Core\\Book\\": "src/Core/src/Book/src/"`, in `composer.json` under the `autoload`.`psr-4` key
747
765
* update Composer autoloader by running the command:
748
766
749
767
```shell
@@ -755,7 +773,7 @@ That's it. The module is now registered.
755
773
We need to configure access to the newly created endpoints.
756
774
Open `config/autoload/authorization.global.php` and append the below route names to the `UserRoleEnum::Guest->value` key:
If we did everything as planned, we can call the `http://0.0.0.0:8080/book` endpoint and create a new book:
808
+
First, we start a local server by executing:
809
+
810
+
```shell
811
+
composer serve
812
+
```
813
+
814
+
If we did everything as planned, we should be able to create a new book by executing the below command:
791
815
792
816
```shell
793
817
curl -X POST http://0.0.0.0:8080/book
@@ -801,7 +825,7 @@ To list the books use:
801
825
curl http://0.0.0.0:8080/books
802
826
```
803
827
804
-
To retrieve a book use:
828
+
To retrieve a book, `curl` one of the links found in the output of the **list books** command, under `_embedded` . `books` . * . `_links` . `self` . `href`
0 commit comments