# Todo List Application
A simple Todo List application developed using Laravel 11 and MySQL. This project is an API-based application with the following features:
- User authentication (token-based).
- CRUD operations for todos.
- Image attachment for todos.
- Database seeding with 1000 todos.
- Email notifications (simulated) when a todo is created or updated.
- Efficient search functionality.
- Unit tests for core functionalities.
- Swagger API documentation.
- Implemented using repository design pattern, service pattern, and observer for better code organization and maintainability.
## Table of Contents
1. [Installation and Setup](#installation-and-setup)
2. [Database Schema](#database-schema)
3. [API Endpoints](#api-endpoints)
4. [Postman Collection](#postman-collection)
5. [Testing](#testing)
6. [Technical Details](#technical-details)
## Installation and Setup
### Prerequisites
- PHP >= 8.2
- Composer
- MySQL
- Node.js (optional, if you choose to use the frontend layer)
### Installation
1. **Clone the Repository:**
```bash
git clone https://github.com/salmazz/PHP_Technical_APP.git
cd PHP_Technical_APP
-
Install Dependencies:
composer install npm install # If using the frontend layer
-
Environment Setup:
Create a
.env
file by copying the example file and configure the environment variables, especially the database settings.cp .env.example .env
Update the
.env
file with your database credentials:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=todo_db DB_USERNAME=root DB_PASSWORD=your_password
-
Generate Application Key:
php artisan key:generate
-
Run Migrations and Seed the Database:
Run the migrations and seed the database with 1000 todos:
php artisan migrate --seed
-
Generate Swagger Documentation:
Generate the Swagger API documentation:
php artisan l5-swagger:generate
-
Run the Application:
Start the local development server:
php artisan serve
The application will be available at
http://localhost:8000
. -
Access Swagger Documentation:
The Swagger UI for API documentation is available at:
http://localhost:8000/api/documentation
The database schema for the application consists of the following tables:
Column | Type | Description |
---|---|---|
id | INT | Primary key |
name | VARCHAR(255) | Name of the user |
VARCHAR(255) | Email of the user (unique) | |
password | VARCHAR(255) | Hashed password |
created_at | TIMESTAMP | Timestamp when the record was created |
updated_at | TIMESTAMP | Timestamp when the record was updated |
Column | Type | Description |
---|---|---|
id | INT | Primary key |
title | VARCHAR(255) | Title of the todo |
description | TEXT | Description of the todo |
status | ENUM | Status of the todo (pending , in_progress , completed , canceled ) |
image | VARCHAR(255) | Path to the attached image |
user_id | INT | Foreign key referencing users.id |
created_at | TIMESTAMP | Timestamp when the record was created |
updated_at | TIMESTAMP | Timestamp when the record was updated |
-
Register:
POST /api/auth/register
- Request:
{ "name": "John Doe", "email": "[email protected]", "password": "password" }
- Request:
-
Login:
POST /api/auth/login
- Request:
{ "email": "[email protected]", "password": "password" }
- Request:
-
Get All Todos:
GET /api/todos
-
Create Todo:
POST /api/todos
- Request (Multipart Form-Data):
title
: stringdescription
: string (optional)status
: enum (pending
,in_progress
,completed
,canceled
)image
: file (optional)
- Request (Multipart Form-Data):
-
Update Todo:
PUT /api/todos/{id}
- Request (Multipart Form-Data):
title
: stringdescription
: string (optional)status
: enum (pending
,in_progress
,completed
,canceled
)image
: file (optional)
- Request (Multipart Form-Data):
-
Delete Todo:
DELETE /api/todos/{id}
-
Update Todo Status:
PATCH /api/todos/{id}/status
- Request:
{ "status": "completed" }
- Request:
- Search Todos:
GET /api/todos?title=example&status=pending&created_at=2024-09-20
A Postman collection is available with all the API endpoints for easy testing and integration. It includes example requests and expected responses.
Link to Postman Collection: Postman Collection Please update the environment variables in Postman:
app_url
: Your app linktoken
: Retrieved after login.
The following unit tests are included:
-
Creating a Todo:
- Test creating a todo and dispatching an email job.
- Check if the todo is saved in the database.
-
Updating a Todo:
- Test updating a todo and dispatching an email job.
- Verify the updated values in the database.
-
Email Notifications:
- Test email notifications are sent on creating or updating a todo.
- Simulated using
Mail::fake()
during tests.
-
Search Functionality:
- Test searching todos by title, status, and creation date.
-
Pagination:
- Test pagination functionality for todos.
To run the tests, use the following command:
php artisan test
- Repository Pattern: Abstracts the data layer, providing a flexible API for data operations.
- Service Pattern: Encapsulates business logic, making the controller lean and focusing on request validation and response.
- Observer Pattern: Observes model events and dispatches jobs for email notifications when a todo is created or updated.
The TodoObserver
is used to listen for created
and updated
events on the Todo
model. It dispatches a job SendTodoNotification
to send an email notification to the user.
- Job: The
SendTodoNotification
job is used to handle the sending of email notifications asynchronously. - Mail: The
TodoNotification
mailable class is used to format the email content.
- Database Schema: Lists the structure of the
users
andtodos
tables, showing the columns and their types. - Postman Collection: Instructions on how to use the provided Postman collection for testing the API endpoints.
- Testing: Lists the different test cases covered and how to run them.
- Technical Details: Explains the design patterns used (repository, service, observer) and how they were implemented.
- Observer Implementation: Describes how the observer is used for handling events.
- Job and Mail Implementation: Details the job and mail classes used for sending email notifications.
You can adjust the content based on the specifics of your implementation and add any additional details you find relevant. If you have any further modifications or additions, feel free to ask!