# KOKUYA Food Order System — Walkthrough

## Apa yang Dikerjakan

Transformasi total backend Laravel dari sistem management properti (Midhouse) menjadi backend food ordering untuk **KOKUYA** (rice bowl brand).

---

## Database (17 Migrations Bersih)

| Migration | Table | Keterangan |
|---|---|---|
| Lama | [users](file:///g:/kerja/kokuya/be/app/Models/User.php#37-41), `roles`, `user_details`, `rekenings`, `announcements`, `seos` | Dipertahankan |
| **Baru** | `menu_categories` | Kategori menu |
| **Baru** | [menus](file:///g:/kerja/kokuya/be/app/Models/MenuCategory.php#20-24) | Item menu + soft delete |
| **Baru** | `promos` | Kode promo + validasi |
| **Baru** | `banners` | Banner iklan |
| **Baru** | `dine_tables` | Meja dine-in |
| **Baru** | `table_reservations` | Booking meja |
| **Baru** | `food_orders` | Order makanan (dine-in/delivery) |
| **Baru** | `food_order_items` | Item per order |

---

## Models

**Baru**: [MenuCategory](file:///g:/kerja/kokuya/be/app/Models/MenuCategory.php#8-25), [Menu](file:///g:/kerja/kokuya/be/app/Models/Menu.php#9-34), [Promo](file:///g:/kerja/kokuya/be/app/Models/Promo.php#8-41), [Banner](file:///g:/kerja/kokuya/be/app/Models/Banner.php#8-20), [DineTable](file:///g:/kerja/kokuya/be/app/Models/DineTable.php#8-26), [TableReservation](file:///g:/kerja/kokuya/be/app/Models/TableReservation.php#9-32), [FoodOrder](file:///g:/kerja/kokuya/be/app/Models/FoodOrder.php#9-51), [FoodOrderItem](file:///g:/kerja/kokuya/be/app/Models/FoodOrderItem.php#8-31)  
**Diperbarui**: [User](file:///g:/kerja/kokuya/be/app/Models/User.php#17-103) (relasi lama dihapus → [foodOrders()](file:///g:/kerja/kokuya/be/app/Models/DineTable.php#21-25), [tableReservations()](file:///g:/kerja/kokuya/be/app/Models/User.php#97-101))  
**Dipertahankan**: [PaymentMid](file:///g:/kerja/kokuya/be/app/Models/PaymentMid.php#8-24), [Seo](file:///g:/kerja/kokuya/be/app/Models/Seo.php#8-36), `UserType`, `UsersDetail`, `rekening`, `Announcement`

---

## Controllers

| Controller | Keterangan |
|---|---|
| [MenuCategoryController](file:///g:/kerja/kokuya/be/app/Http/Controllers/MenuCategoryController.php#10-127) | CRUD kategori, public & admin |
| [MenuController](file:///g:/kerja/kokuya/be/app/Http/Controllers/MenuController.php#11-223) | List menu, featured, slug, admin CRUD + image upload + soft delete |
| [PromoController](file:///g:/kerja/kokuya/be/app/Http/Controllers/PromoController.php#10-192) | Listing promo aktif + validasi kode promo dengan hitung diskon |
| [BannerController](file:///g:/kerja/kokuya/be/app/Http/Controllers/BannerController.php#10-126) | Image upload, CRUD admin |
| [DineTableController](file:///g:/kerja/kokuya/be/app/Http/Controllers/DineTableController.php#10-127) | Status meja realtime + cek ketersediaan slot waktu |
| [TableReservationController](file:///g:/kerja/kokuya/be/app/Http/Controllers/TableReservationController.php#11-186) | Booking, conflict detection, kapasitas, admin confirm/complete |
| [FoodOrderController](file:///g:/kerja/kokuya/be/app/Http/Controllers/FoodOrderController.php#16-309) | Buat order (dine-in/delivery), promo auto-apply, invoice generation, DB transaction |
| [DashboardController](file:///g:/kerja/kokuya/be/app/Http/Controllers/DashboardController.php#12-111) | Statistik today/bulan, menu populer, order terbaru |
| [PaymentMidController](file:///g:/kerja/kokuya/be/app/Http/Controllers/PaymentMidController.php#14-216) | *Diadaptasi*: [handleCallback](file:///g:/kerja/kokuya/be/app/Http/Controllers/PaymentMidController.php#135-175) sekarang marking `FoodOrder.payment_status = paid` saat settlement |

---

## Routes (api.php)

Rewrite total dengan struktur bersih dan konsisten:

| Group | Contoh Endpoint |
|---|---|
| Auth | `POST /api/auth/login`, `POST /api/auth/register` |
| Google OAuth | `GET /api/auth/google`, `GET /api/auth/google/callback` |
| User & Profile | `GET /api/auth/me`, `PUT /api/users/{id}/profile` |
| SEO | `GET /api/seo/{pageKey}` |
| Midtrans | `POST /api/payments/midtrans/snap-token`, `POST /api/payments/midtrans/callback` |
| Transfer/Rekening | `GET /api/rekening` (public) |
| Menus (public) | `GET /api/menus`, `GET /api/menus/featured`, `GET /api/menus/{slug}` |
| Promo (public) | `GET /api/promos`, `POST /api/promos/check` |
| Banners (public) | `GET /api/banners` |
| Dine Tables (public) | `GET /api/dine-tables`, `GET /api/dine-tables/availability` |
| Food Orders (auth) | `POST /api/food-orders`, `GET /api/food-orders/my` |
| Reservasi (auth) | `POST /api/table-reservations`, `GET /api/table-reservations/my` |
| Admin menus | `GET /api/admin/menus`, `POST /api/admin/menus` |
| Admin orders | `GET /api/admin/food-orders`, `PATCH /api/admin/food-orders/{id}/status` |
| Admin dashboard | `GET /api/admin/dashboard` |

---

## Seeder Dummy Data

- **3 roles**: superadmin, admin, customer
- **3 users**: `superadmin@kokuya.id`, `admin@kokuya.id`, `customer@kokuya.id` (password: `password`)
- **4 rekening**: BCA, BNI, BRI, GoPay
- **6 kategori menu** + **17 item menu** lengkap dengan deskripsi, harga, kalori
- **3 promo**: `KOKUYA10` (10%), `HEMAT15` (Rp 15rb), `WKND20` (20%)
- **3 banner** placeholder
- **10 meja** (Indoor A1-B3, Outdoor C1-C3)
- **6 halaman SEO** KOKUYA (homepage, menu, order, promo, reservation, about)

---

## Hasil Verifikasi

```
✅ migrate:fresh --seed       → Exit 0, 17 migrations bersih
✅ Route list                 → Semua route baru tampil, tidak ada error/exception
✅ No property routes         → Property/room/booking/fasilitas sudah tidak ada
```
