This scope of task is to implement a RESTful API for before-mentioned phone-book to be used by our frontend developers. Customers should be able to perform the following actions:
- Add other customers as contact
- Edit created contacts.
- Delete existing contacts
- Search for contacts by name
- first name
- last name
- address information
- phone number
- birthday
- email address
- Picture (optional)
Phonebook-Api Application core business logic persists in src
folder. Uses the MVC architecture with loosely coupled code and follows the best practices SOLID principle.
- The application CRUD services can be access via
- API Swagger URL:
BASE_URL/api/
- API Doc URL:
BASE_URL/api/docs?ui=re_doc
I uses the API Platform Component with Symfony
which conforms to the Open API specification, also get auto-generated documentation via Swagger.
src/Entity/Contacts.php
is our Entity file which have all the fields/properties related to contacts table.- The most important thing to note is the inclusion of
@ApiResource
which declares this entity to be used as an API. src/Controller/SearchByName.php
, expose a new route that’s different than the default ones to search name incontact table
src/Controller/ContactProfileController.php
Modify/Upate the existing POST route to achieve profile image upload functionality
- Feature test cases class
ContactsTest.php
will be found intest/ContactsTest.php
. - I tried to cover all the positive and negative test cases of
GET & POST
in this class.
- Clone the repository.
- Copy .env.example to .env
cp .env.example .env
- Install packages by running
composer install
.
For demonstration purpose, I used database named phonebook
. Configurations can be visited in .env
file located at the root of the project.
DATABASE_URL="mysql://root:[email protected]:3306/phonebook?serverVersion=5.7&charset=utf8mb4"
.
You can change your DB changes
DATABASE_URL="mysql://DB_USER:DB_PASSWORD@IP:PORT/DB_NAME?serverVersion=5.7&charset=utf8mb4"
.
Now, create database via doctrine command
php ./bin/console doctrine:database:create
Now, add contacts
table schema via doctrine command
php bin/console doctrine:schema:update --force
- Run application
symfony server:start
- Visit started development server localhost:PORT/api
- To run the application test suite, it is required to create test database in our case
phonebook_test
- Command run the unit test suite
php bin/phpunit