Proyek Penjualan Kendaraan REST API Laravel adalah sebuah aplikasi berbasis Laravel yang menyediakan API untuk mengelola penjualan kendaraan.
Sebelum memulai instalasi, pastikan Anda telah memenuhi prasyarat berikut:
- PHP v8.0
- Composer
- MongoDB v4.2
- Git
Berikut adalah langkah-langkah untuk menginstal proyek Penjualan Kendaraan REST API Laravel:
-
Clone Repositori
Buka terminal atau command prompt dan jalankan perintah berikut untuk mengkloning repositori:
git clone https://github.com/shofistwn/penjualan-kendaraan.git
-
Pindah ke Direktori Proyek
Masuk ke direktori proyek yang telah di-kloning dengan menjalankan perintah:
cd penjualan-kendaraan
-
Instal Dependensi
Jalankan perintah berikut untuk menginstal semua dependensi yang diperlukan oleh proyek:
composer install
-
Konfigurasi Lingkungan
Salin file
.env.example
menjadi.env
dengan menjalankan perintah:cp .env.example .env
-
Generate Kunci Aplikasi
Jalankan perintah berikut untuk menghasilkan kunci aplikasi:
php artisan key:generate
-
Konfigurasi Database
Buka file
.env
dan ubah pengaturan database seperti berikut:DB_CONNECTION=mongodb DB_HOST=127.0.0.1 DB_PORT=27017 DB_DATABASE=penjualan_kendaraan DB_USERNAME= DB_PASSWORD=
-
Mengimpor Database
Import file database yang berada di
/documents/database/penjualan_kendaraan.agz
-
Mengimpor Collection Postman
Import file collection yang berada di
/documents/postman/penjualan-kendaraan.postman_collection.json
-
Jalankan Server Lokal
Terakhir, jalankan server lokal dengan perintah:
php artisan serve
Server akan berjalan di
http://localhost:8000
.
Berikut adalah dokumentasi API yang tersedia dalam proyek ini.
-
Register
Request:
POST /api/v1/auth/register Body: { "name" : "John Doe" "email": "[email protected]", "password": "password" }
Response:
{ "success": true, "message": "Pendaftaran berhasil", "data": { "_id": "647949443cac74567d0f4919", "email": "[email protected]", "name": "John Doe", "password": "$2y$10$W0ttWIhBPd5ULcwWkV6eM..." } }
-
Login
Request:
POST /api/v1/auth/login Header: Authorization: Bearer <JWT Token> Body: { "email": "[email protected]", "password": "password" }
Response:
{ "success": true, "message": "Login berhasil", "data": { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ...", "token_type": "bearer", "expires_in": 3600 } }
-
Logout
Request:
POST /api/v1/auth/login Header: Authorization: Bearer <JWT Token>
Response:
{ "success": true, "message": "Logout berhasil", "data": [] }
-
Mengambil Stok Kendaraan
Request:
POST /api/v1/vehicles/stock Header: Authorization: Bearer <JWT Token>
Response:
{ "success": true, "message": "Dapatkan stok kendaraan", "data": [ { "_id": "64788d11904ea19c110f2425", "harga": "25000000", "motor": { "mesin": "150cc", "tipe_suspensi": "Telescopic", "tipe_transmisi": "Manual" }, "tahun_keluaran": "2022", "terjual": false, "tipe_kendaraan": "motor", "warna": "Merah" }, { "_id": "64788d58904ea19c110f2426", "harga": "850000000", "mobil": { "mesin": "1200cc", "kapasitas_penumpang": "7", "tipe": "SUV" }, "tahun_keluaran": "2023", "terjual": false, "tipe_kendaraan": "mobil", "warna": "Merah" } ] }
-
Menjual Kendaraan
Request:
POST /api/v1/vehicles/sell Header: Authorization: Bearer <JWT Token> Body: { "kendaraan_id": "64788d11904ea19c110f2425" }
Response:
{ "success": true, "message": "Kendaraan terjual", "data": { "_id": "64788d11904ea19c110f2425", "harga": "25000000", "motor": { "mesin": "150cc", "tipe_suspensi": "Telescopic", "tipe_transmisi": "Manual" }, "tahun_keluaran": "2022", "terjual": true, "tipe_kendaraan": "motor", "warna": "Merah" } }
-
Laporan Penjualan
Request:
POST /api/v1/vehicles/sales-report Header: Authorization: Bearer <JWT Token>
Response:
{ "success": true, "message": "Dapatkan laporan penjualan", "data": { "mobil": { "terjual": 1, "tersisa": 1, "total": 2 }, "motor": { "terjual": 1, "tersisa": 2, "total": 3 } } }
-
Menambahkan Kendaraan Motor
Request:
POST /api/v1/vehicles/add-motor Header: Authorization: Bearer <JWT Token> Body: { "tahun_keluaran": "2018", "warna": "Putih", "harga": "40000000", "mesin": "400cc", "tipe_suspensi": "Mono Shock", "tipe_transmisi": "Automatic" }
Response:
{ "success": true, "message": "Kendaraan berhasil ditambahkan", "data": { "_id": "647948503cac74567d0f4916", "harga": "40000000", "motor": { "mesin": "400cc", "tipe_suspensi": "Mono Shock", "tipe_transmisi": "Automatic" }, "tahun_keluaran": "2018", "terjual": false, "tipe_kendaraan": "motor", "warna": "Putih" } }
-
Menambahkan Kendaraan Mobil
Request:
POST /api/v1/vehicles/add-car Header: Authorization: Bearer <JWT Token> Body: { "tahun_keluaran": "2022", "warna": "Putih", "harga": "300000000", "mesin": "2000cc", "kapasitas_penumpang": "5", "tipe": "MPV" }
Response:
{ "success": true, "message": "Kendaraan berhasil ditambahkan", "data": { "_id": "6479487d3cac74567d0f4917", "harga": "300000000", "motor": { "mesin": "2000cc", "kapasitas_penumpang": "5", "tipe": "MPV" }, "tahun_keluaran": "2022", "terjual": false, "tipe_kendaraan": "mobil", "warna": "Putih" } }