# 🚀 Quick Start - Backend Setup

## Prerequisites
- PHP 8.2+
- Composer
- MySQL

## Installation (5 Menit!)

```bash
# 1. Masuk ke folder backend
cd backend

# 2. Install dependencies
composer install

# 3. Setup environment
cp .env.example .env
php artisan key:generate

# 4. Edit .env - sesuaikan database config
# DB_DATABASE=ksp_perumnas
# DB_USERNAME=root
# DB_PASSWORD=

# 5. Create database
mysql -u root -p
CREATE DATABASE ksp_perumnas;
exit;

# 6. Run migrations
php artisan migrate

# 7. (Optional) Seed data testing
php artisan db:seed

# 8. Jalankan server
php artisan serve
```

## ✅ Test API

```bash
# Test endpoint root
curl http://localhost:8000

# Test login (jika sudah seed)
curl -X POST http://localhost:8000/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"budisantoso","password":"password123"}'
```

## 🔗 Endpoints

**Base URL:** `http://localhost:8000/api`

### Public
- POST `/login` - Login
- POST `/register` - Register
- GET `/jenis-simpanan` - Master simpanan
- GET `/jenis-pinjaman` - Master pinjaman

### Protected (Butuh Token)
- GET `/dashboard` - Dashboard data
- GET `/simpanan` - List simpanan
- GET `/pinjaman` - List pinjaman
- GET `/products` - List produk
- POST `/checkout` - Checkout
- GET `/notifications` - Notifikasi

**Lihat [README.md](README.md) untuk dokumentasi lengkap.**

## 📱 Flutter Integration

Update file `lib/core/constants/api_constants.dart`:

```dart
class ApiConstants {
  static const String baseUrl = 'http://localhost:8000/api'; // Development
  // static const String baseUrl = 'https://app.koperasi.perumnas.co.id/api'; // Production
}
```

## ⚠️ Troubleshooting

### Error "Please provide a valid cache path"
```bash
mkdir -p storage/framework/{sessions,views,cache}
chmod -R 775 storage bootstrap/cache
```

### Migration error
```bash
php artisan migrate:fresh --seed
```

### CORS error dari Flutter
Pastikan di `.env`:
```env
SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1
```

---

**Selesai! Backend siap digunakan. 🎉**
