SmartExpose / AllMyHomes
This task aims to test the basic knowledge for creating RESTful APIs in Cake3. The instructions bellow describe the needed set up, task to be implemented and expected results.
In this section you can see what are the necessary steps to run this trial task. If you have a problem setting up this project, contact the developer responsible for supervising your application.
- Check the system requirements:
- Apache server with PHP 5.6+ and Intl extension enabled
- MySql server 15.0+
- Clone this repository into a accessible folder (e.g. htdocs)
- Run
composer install - Create a database using the file
DB.sqlin this folder - Update data sources in the file
config/app.phpconnecting to your mysql server, if necessary
Create three controllers Genres, Authors and Books, that provide RESTful endpoints for:
Returns all genres available. The response format should be:
[
{
"id": "int",
"name": "string"
}
]Returns all authors whom first or second name match the query param name.
The response format should be:
[
{
"id": "int",
"first_name": "string",
"second_name": "string"
}
]Returns all books for given genre. Each book should contain its author as well the genre information:
[
{
"id": "int",
"title": "string",
"pages": "int",
"genre": {
"id": "int",
"name": "string"
},
"author": {
"id": "int",
"first_name": "string",
"second_name": "string"
}
}
]Returns all books for given author. The response format is the same as getting books per genre:
[
{
"id": "int",
"title": "string",
"pages": "int",
"genre": {
"id": "int",
"name": "string"
},
"author": {
"id": "int",
"first_name": "string",
"second_name": "string"
}
}
]Creates a new book and return its ID. The request body should be:
{
"genre_id": "int",
"author_id": "int",
"title": "string",
"pages": "int"
}The response should contain the id of the newly created book:
{
"id": "int"
}Updates a book. The request body should be:
{
"genre_id": "int",
"author_id": "int",
"title": "string",
"pages": "int"
}Removes a book.
This repository already contains tests with expected response bodies and codes. At the end of the implementation, all the tests should run.
Warning: If you use
baketo create the models and tables, don't forget to skip the fixtures and tests, otherwise they will be overwritten
While running the tests, check how good is the code coverage:
./vendor/bin/phpunit --coverage-textIf the coverage for the Genres, Authors and Books controllers is not 100%, write tests to cover the missing lines.
To send your solution, create a new branch with your name.surname,
commit your solution into it and push it to this repository.
Done that, send an email to the developer responsible for supervising your application.
For the evaluation of this trial task, those aspects are considered:
- Implementation follows specifications: routes comply with REST standard
and responses have expected data (tests are green)
./vendor/bin/phpunit - Code quality: the code is simple, clean and follow CakePHP Standards
(code sniffer does not find errors)
./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src