This project is a Laravel-based application designed to manage integrations with different marketplaces. It includes user authentication via Laravel Passport, and API endpoints for registering users, managing integrations, and running associated commands. The project also contains comprehensive unit and API tests.
Before you begin, ensure you have met the following requirements:
- PHP 8.0 or higher
- Composer
- Laravel 11.x
- MySQL or any other supported database
Follow these steps to set up the project locally:
-
Clone the Repository:
git clone git@github.com:MenarSelamet/laravel-challenge-project.git cd laravel-challenge-project
-
Install Dependencies:
Install the PHP dependencies using Composer:
composer install
-
Environment Setup:
-
Copy the
.env.example
file to.env
:cp .env.example .env
-
Generate an application key:
php artisan key:generate
-
-
Database Configuration:
-
Open the
.env
file and set your database connection details:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password
-
Run the following command to migrate your database schema:
php artisan migrate
Install and configure Laravel Passport for API authentication:
-
Install Passport:
php artisan passport:install
-
Define an
api
authentication guard:Define an
api
authentication guard and set thedriver
option topassport
:'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],
To start the Laravel development server, run:
php artisan serve
The application will be available at http://127.0.0.1:8000
.
You can run the tests using PHPUnit:
php artisan test
- API Tests:
- Registration validation (e.g., invalid email, missing name)
- Unit Tests:
- Integration management (create, update, delete)
Here is a summary of the API endpoints provided by this application:
-
POST
/register
: Register a new user.-
Request Body:
{ "name": "John Doe", "email": "john@example.com", "password": "password123" }
-
Response:
201 Created
: User successfully registered.422 Unprocessable Entity
: Validation error.
-
-
POST
/login
: Obtain an OAuth2 token using Laravel Passport.-
Request Body:
{ "email": "john@example.com", "password": "password123" }
-
Response:
200 OK
: Token generated.401 Unauthorized
: Invalid credentials.
-
-
POST
/integration
: Add a new marketplace integration.-
Request Body:
{ "marketplace": "n11|trendyol", "username": "user", "password": "pass" }
-
Response:
201 Created
: Integration added.403 Forbidden
: Unauthorized access.
-
-
PUT
/integration/{id}
: Update an existing integration.-
Request Body:
{ "marketplace": "n11|trendyol", "username": "newuser", "password": "newpass" }
-
Response:
200 OK
: Integration updated.404 Not Found
: Integration not found.
-
-
DELETE
/integration/{id}
: Delete an integration.- Response:
204 No Content
: Integration deleted.403 Forbidden
: Unauthorized access.
- Response:
The following Artisan commands are available for managing integrations:
-
Create Integration:
php artisan integration:store {marketplace} {username} {password}
-
Update Integration:
php artisan integration:update {id} {marketplace} {username} {password}
-
Delete Integration:
php artisan integration:destroy {id}
A Postman collection is included in the project to facilitate testing. You can import the collection into Postman to test the API endpoints directly.
-
Import the Collection:
- Download the collection file laravel_challenge_project.postman_collection.json from the repository.
- Open Postman and import the collection.
-
Using the Collection:
- The collection includes predefined requests for all API endpoints.
- Adjust the environment variables in Postman (e.g.,
base_url
,auth_token
) to match your setup.
- Clone the repository and navigate to the project directory.
- Install dependencies with Composer.
- Set up your
.env
file and generate an application key. - Migrate your database schema.
- Install and configure Laravel Passport.
- Run the Laravel development server.
- Use Postman to test the API endpoints and manage integrations.
- 403 Forbidden Errors:
- Ensure your token is correctly included in the
Authorization
header. - Check your Passport middleware configuration.
- Ensure your token is correctly included in the
- 500 Internal Server Errors:
- Check the Laravel logs (
storage/logs/laravel.log
) for detailed error messages. - Verify your environment configuration (
.env
), especially database and Passport settings.
- Check the Laravel logs (