The Reading Recommendation System is a web application built using Laravel that allows users to submit their reading intervals for various books and provides recommendations based on the most read books by the users. The system also sends a thank-you SMS to users after submitting their reading intervals. This Laravel backend system consists of two main APIs:
- API to submit a user reading interval.
- API to calculate the most recommended five books.
- Create, update, and delete reading intervals for users.
- Retrieve the most recommended books based on reading activity.
- Secure endpoints with authentication (optional).
- Laravel: PHP web application framework
- MySQL: Relational database management system
- Postman: API development and testing tool
- Clone the repository to your local machine.
- Install dependencies by running
composer install
. - Create a
.env
file by copying the.env.example
file and configure your environment variables. - Generate application key by running
php artisan key:generate
. - Migrate the database by running
php artisan migrate
. - Optionally, seed the database with sample data by running
php artisan db:seed
. - Start the development server by running
php artisan serve
.
-
Add a reading interval: Send a POST request to /api/reading-intervals with the following JSON payload:
{ "user_id": 1, "book_id": 1, "starting_page": 10, "ending_page": 30 }
-
Response:** 200 OK
{ "message": "Reading interval submitted successfully." }
-
Response: Success message indicating the reading interval submission.
-
SMS Sent: A thank you message is sent to the user using the configured SMS provider.
- Send a GET request to /api/recommended-books to retrieve the most read books.
- Response: 200 OK
[ { "book_id": 1, "book_name": "Clean Code", "num_of_read_pages": "45" }, { "book_id": 2, "book_name": "Harry Potter", "num_of_read_pages": "21" } ]
You can find a Postman collection with example requests in this Postman Collection file.
Unit tests are implemented using PHPUnit. To run the tests, execute the following command:
php artisan test
You should see output similar to the following:
Attempt | Test Case | Duration |
---|---|---|
PASS | submit reading interval | 1.30s |
PASS | recommend books | 0.02s |
Tests: 2 passed (4 assertions)
Duration: 1.46s
- 400 Bad Request: Invalid request format or missing required parameters.
- 401 Unauthorized: Authentication failure.
- 404 Not Found: Resource not found.
- 500 Internal Server Error: Unexpected server error.
The system supports two SMS providers and switches between them based on the environment variable.
- Mock SMS Provider 1: https://run.mocky.io/v3/8eb88272-d769-417c-8c5c-159bb023ec0a
- Mock SMS Provider 2: https://run.mocky.io/v3/268d1ff4-f710-4aad-b455-a401966af719
© Ahmed Hamza El-Sherif
Connect with me on LinkedIn or check out my GitHub profile. Feel free to drop me an email.
Special thanks to the Koinz team for providing the opportunity to work on this project.