From c5486575a3eef02737ee2d787c2e6b192218e5ee Mon Sep 17 00:00:00 2001 From: ariefabbauftech-ai Date: Mon, 1 Sep 2025 14:29:01 +0700 Subject: [PATCH] [Kategori & Api Ulasan] done --- .../Http/Controllers/Api/ReviewController.php | 72 +++++++ backend/app/Models/Review.php | 18 ++ ...2025_09_01_071755_create_reviews_table.php | 24 +++ .../resources/views/admin/dashboard.blade.php | 196 +++++++++--------- backend/routes/api.php | 5 +- 5 files changed, 218 insertions(+), 97 deletions(-) create mode 100644 backend/app/Http/Controllers/Api/ReviewController.php create mode 100644 backend/app/Models/Review.php create mode 100644 backend/database/migrations/2025_09_01_071755_create_reviews_table.php diff --git a/backend/app/Http/Controllers/Api/ReviewController.php b/backend/app/Http/Controllers/Api/ReviewController.php new file mode 100644 index 0000000..69731ac --- /dev/null +++ b/backend/app/Http/Controllers/Api/ReviewController.php @@ -0,0 +1,72 @@ +json(Review::all(), 200); + } + + // Simpan ulasan baru + public function store(Request $request) + { + $validated = $request->validate([ + 'rating' => 'required|integer|min:1|max:5', + 'message' => 'required|string', + 'name' => 'required|string|max:100', + 'city' => 'required|string|max:100', + ]); + + $review = Review::create($validated); + + return response()->json([ + 'message' => 'Ulasan berhasil disimpan', + 'data' => $review + ], 201); + } + + // Tampilkan ulasan tertentu + public function show($id) + { + $review = Review::findOrFail($id); + return response()->json($review, 200); + } + + // Update ulasan + public function update(Request $request, $id) + { + $review = Review::findOrFail($id); + + $validated = $request->validate([ + 'rating' => 'integer|min:1|max:5', + 'message' => 'string', + 'name' => 'string|max:100', + 'city' => 'string|max:100', + ]); + + $review->update($validated); + + return response()->json([ + 'message' => 'Ulasan berhasil diperbarui', + 'data' => $review + ], 200); + } + + // Hapus ulasan + public function destroy($id) + { + $review = Review::findOrFail($id); + $review->delete(); + + return response()->json([ + 'message' => 'Ulasan berhasil dihapus' + ], 200); + } +} diff --git a/backend/app/Models/Review.php b/backend/app/Models/Review.php new file mode 100644 index 0000000..b274073 --- /dev/null +++ b/backend/app/Models/Review.php @@ -0,0 +1,18 @@ +id(); + $table->tinyInteger('rating'); // nilai bintang 1–5 + $table->text('message'); + $table->string('name'); + $table->string('city'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('reviews'); + } +}; diff --git a/backend/resources/views/admin/dashboard.blade.php b/backend/resources/views/admin/dashboard.blade.php index 871947f..b76f564 100644 --- a/backend/resources/views/admin/dashboard.blade.php +++ b/backend/resources/views/admin/dashboard.blade.php @@ -1,107 +1,115 @@ + - - - Halaman Dasbor - - - + + + Halaman Dasbor + + + + -
- -
-

Halaman Dasbor

+
+ +
+

Halaman Dasbor

-
-
- - {{ \Carbon\Carbon::now()->translatedFormat('l, d F Y') }} +
+
+ + {{ \Carbon\Carbon::now()->translatedFormat('l, d F Y') }} +
+ + +
+ @csrf + +
+
- -
- @csrf - -
-
+ +
+
+
+
+
Kategori
+

10

+
+ +
+
+
+
+
+
Templat
+

20

+
+ +
+
+
+
+
+
Pelanggan
+

24

+
+ +
+
+
+ + +
+ Berhasil login sebagai {{ auth('admin')->user()->name }} +
- -
-
-
-
-
Kategori
-

10

-
- -
-
-
-
-
-
Templat
-

20

-
- -
-
-
-
-
-
Pelanggan
-

24

-
- -
-
-
- - -
- Berhasil login sebagai {{ auth('admin')->user()->name }} -
-
- + diff --git a/backend/routes/api.php b/backend/routes/api.php index 889937e..bb8314e 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -2,6 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Api\ReviewController; /* |-------------------------------------------------------------------------- @@ -14,6 +15,4 @@ use Illuminate\Support\Facades\Route; | */ -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { - return $request->user(); -}); +Route::apiResource('reviews', ReviewController::class);