diff --git a/backend-baru/app/Http/Controllers/Api/PelangganApiController.php b/backend-baru/app/Http/Controllers/Api/PelangganApiController.php index 537f1cf..305492a 100644 --- a/backend-baru/app/Http/Controllers/Api/PelangganApiController.php +++ b/backend-baru/app/Http/Controllers/Api/PelangganApiController.php @@ -6,46 +6,77 @@ use App\Http\Controllers\Controller; use App\Models\Pelanggan; use App\Models\Template; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; class PelangganApiController extends Controller { // 🔹 Simpan pesanan pelanggan via API - public function store(Request $request) + public function store(Request $request) { - $request->validate([ - 'nama_pemesan' => 'required|string|max:255', - 'email' => 'required|email', - 'no_tlpn' => 'required|string|max:20', - 'template_id' => 'required|exists:templates,id', - 'form' => 'required|array', - ]); + try { + $validated = $request->validate([ + 'nama_pemesan' => 'required|string|max:255', + 'email' => 'required|email', + 'no_tlpn' => 'required|string|max:20', + 'template_slug' => 'required|exists:templates,slug', + 'form' => 'required|array', + 'foto.*' => 'nullable|image|mimes:jpeg,png,jpg|max:2048', + ]); - $template = Template::findOrFail($request->input('template_id')); + $template = Template::where('slug', $request->input('template_slug'))->firstOrFail(); - // 🔸 Generate kode undangan unik - $invitationCode = 'INV-' . strtoupper(Str::random(6)); - while (Pelanggan::where('invitation_code', $invitationCode)->exists()) { + // Generate unique invitation code $invitationCode = 'INV-' . strtoupper(Str::random(6)); + while (Pelanggan::where('invitation_code', $invitationCode)->exists()) { + $invitationCode = 'INV-' . strtoupper(Str::random(6)); + } + + // Handle file uploads + $fotoPaths = []; + if ($request->hasFile('foto')) { + foreach ($request->file('foto') as $file) { + $path = $file->store('photos', 'public'); // Store in storage/public/photos + $fotoPaths[] = $path; + } + } + + // Save customer data + $pelanggan = Pelanggan::create([ + 'nama_pemesan' => $validated['nama_pemesan'], + 'email' => $validated['email'], + 'no_tlpn' => $validated['no_tlpn'], + 'template_id' => $template->id, + 'form' => array_merge($validated['form'], ['foto' => $fotoPaths]), + 'harga' => $template->harga, + 'status' => 'menunggu', + 'invitation_code' => $invitationCode, + ]); + + return response()->json([ + 'success' => true, + 'message' => 'Pesanan berhasil dibuat', + 'data' => $pelanggan, + ], 201); + + } catch (\Illuminate\Validation\ValidationException $e) { + return response()->json([ + 'success' => false, + 'message' => 'Validation failed', + 'errors' => $e->errors(), + ], 422); + } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { + return response()->json([ + 'success' => false, + 'message' => 'Template not found', + ], 404); + } catch (\Exception $e) { + Log::error('Error in store method: ' . $e->getMessage()); + return response()->json([ + 'success' => false, + 'message' => 'An error occurred: ' . $e->getMessage(), + ], 500); } - - // 🔸 Simpan data pelanggan baru - $pelanggan = Pelanggan::create([ - 'nama_pemesan' => $request->nama_pemesan, - 'email' => $request->email, - 'no_tlpn' => $request->no_tlpn, - 'template_id' => $template->id, - 'form' => $request->input('form'), - 'harga' => $template->harga, - 'status' => 'menunggu', - 'invitation_code' => $invitationCode, - ]); - - return response()->json([ - 'success' => true, - 'message' => 'Pesanan berhasil dibuat', - 'data' => $pelanggan, - ], 201); } // 🔹 Ambil semua data pelanggan diff --git a/backend-baru/database/migrations/2025_10_02_043030_create_templates_table.php b/backend-baru/database/migrations/2025_10_02_043030_create_templates_table.php index 8fd1189..a23b31e 100644 --- a/backend-baru/database/migrations/2025_10_02_043030_create_templates_table.php +++ b/backend-baru/database/migrations/2025_10_02_043030_create_templates_table.php @@ -8,7 +8,8 @@ return new class extends Migration { public function up(): void { Schema::create('templates', function (Blueprint $table) { $table->id(); - $table->string('nama_template'); + $table->string('nama_template')->unique(); + $table->string('slug')->unique(); $table->decimal('harga', 10, 2)->default(0); $table->string('foto')->nullable(); $table->enum('paket', ['starter', 'basic', 'premium'])->default('starter'); diff --git a/backend-baru/routes/web.php b/backend-baru/routes/web.php index 0e0936c..72761ec 100644 --- a/backend-baru/routes/web.php +++ b/backend-baru/routes/web.php @@ -6,7 +6,7 @@ use App\Http\Controllers\DashboardController; use App\Http\Controllers\KategoriController; use App\Http\Controllers\TemplateController; use App\Http\Controllers\PelangganController; -use App\Http\Controllers\ReviewController; // Pastikan ini controller web, bukan API +use App\Http\Controllers\Api\ReviewController; use Illuminate\Support\Facades\Auth; // ============================ diff --git a/proyek-frontend/app/pages/form/undangan-pernikahan-premium.vue b/proyek-frontend/app/pages/form/undangan-pernikahan-premium.vue index c12edbd..84f7100 100644 --- a/proyek-frontend/app/pages/form/undangan-pernikahan-premium.vue +++ b/proyek-frontend/app/pages/form/undangan-pernikahan-premium.vue @@ -16,7 +16,7 @@ class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-400 focus:border-blue-400 outline-none transition" /> - @@ -29,19 +29,19 @@

Mempelai Pria

- - - - - - -
@@ -50,19 +50,19 @@

Mempelai Wanita

- - - - - - -
@@ -72,74 +72,71 @@

💌 Cerita Kita

-
- -
-

💳 Rekening & Musik

-
- - - -
- + + +
+

💳 Rekening & Musik

+
+ + + +
+
+
-

🖼️ Galeri Foto

- -
- - - - - - - -
-
- - -
- - - -
-
-
- +

🖼️ Galeri Foto

+
+ + +
+
+ + +
+ +
+
+
@@ -154,37 +151,40 @@
- - -