Skip to content

bimprakosoo/api-transaction-mongodb

Repository files navigation

Laravel 8 with MongoDB

Prerequisites

Before getting started, make sure you have the following requirements installed on your system:

  1. PHP 8
  2. Laravel 8
  3. MongoDB 4.2

Installation

Follow these steps to get the project up and running on your local machine:

    1. Clone the repository to your local machine:
git clone https://github.com/bimprakosoo/test-inosoft.git
    1. Navigate to the project directory:
cd your-repository
    1. Install the project dependencies using Composer:
composer install
    1. Install MongoDB on your system. Refer to the official MongoDB documentation for installation instructions specific to your operating system: MongoDB Installation
    2. Set up your database configuration by creating a .env file. You can use the .env.example file as a template:
cp .env.example .env

Update the following lines in the .env file with your MongoDB connection details:

DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
    1. Generate an application key:
php artisan key:generate
      1. Install the tymon/jwt-auth
      package for JSON Web Token authentication:
composer require tymon/jwt-auth
    1. Generate the JWT secret key:
php artisan jwt:secret
    1. Run the database migrations to create the necessary tables:
php artisan migrate
    1. (Optional) Run the database seeder to populate the database with dummy data:
php artisan db:seed
    1. Run the unit tests to ensure everything is set up correctly:
php artisan test
    1. Start the development server:
php artisan serve

The application will be available at http://127.0.0.1:8000.

Usage

Provide instructions and examples for users to understand and use your project. Include examples of API endpoints, how to make requests, and expected responses.

Register and Login

Before testing the API endpoints, you need to register and login to obtain an access token. Follow these steps:

  1. Register a new user:
  2. Send a POST request to http://127.0.0.1:8000/api/register with the following parameters:

    {
      "name": "Your Name",
      "email": "[email protected]",
      "password": "your-password"
    }
  3. Login with the registered user:
  4. Send a POST request to http://127.0.0.1:8000/api/login with the following parameters:

    {
      "email": "[email protected]",
      "password": "your-password"
    }

    The response will include an access token that you can use to authenticate subsequent requests.

    Testing the API

    Once you have obtained the access token, you can test the API endpoints using a tool like Postman. Set the "Authorization" header in your requests with the access token in the following format:

    Authorization: Bearer <access_token>

    Here are some example API endpoints you can test:

    • Check Stock: Send a POST request to http://127.0.0.1:8000/api/kendaraan/check-stock to check the stock of a vehicle.
    • Create Kendaraan Transaction: Send a POST request to http://127.0.0.1:8000/api/kendaraan-transactions to create a new Kendaraan Transaction.
    • Get Sales Report: Send a GET request to http://127.0.0.1:8000/api/sales-report to retrieve the sales report.

    Make sure to include the required parameters and provide the necessary authentication headers for each request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published