Skip to content

Commit

Permalink
memperbaiki program yang hilang karena ezra
Browse files Browse the repository at this point in the history
  • Loading branch information
NataNaraNPS committed Dec 31, 2024
1 parent 3c52f6f commit cacbce3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/PembelianProdukController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ public function store(Request $request)
}
}

public function index()
{
$pembelian = PembelianProduk::with('detailPembelian')->get();
return response()->json($pembelian);
}

public function show($id)
{
$pembelian = PembelianProduk::with('detailPembelian')->find($id);

if (!$pembelian) {
return response()->json(['error' => 'Data pembelian tidak ditemukan'], 404);
}

return response()->json($pembelian);
}


public function update(Request $request, $id)
{
$pembelian = PembelianProduk::find($id);
Expand Down
24 changes: 12 additions & 12 deletions app/Http/Controllers/ProdukController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function show($id)
'message' => 'Data produk berhasil diambil.',
'data' => $produk,
], 200);
} catch (ModelNotFoundException $e) {
return response()->json([
'message' => 'Produk tidak ditemukan.',
], 404);
// } catch (ModelNotFoundException $e) {
// return response()->json([
// 'message' => 'Produk tidak ditemukan.',
// ], 404);
} catch (\Exception $e) {
return response()->json([
'message' => 'Gagal mengambil data produk.',
Expand Down Expand Up @@ -98,10 +98,10 @@ public function update(Request $request, $id)
'message' => 'Produk berhasil diperbarui.',
'data' => $produk,
], 200);
} catch (ModelNotFoundException $e) {
return response()->json([
'message' => 'Produk tidak ditemukan.',
], 404);
// } catch (ModelNotFoundException $e) {
// return response()->json([
// 'message' => 'Produk tidak ditemukan.',
// ], 404);
} catch (\PDOException $e) {
return response()->json([
'message' => 'Terjadi kesalahan pada koneksi database.',
Expand All @@ -125,10 +125,10 @@ public function destroy($id)
return response()->json([
'message' => 'Produk berhasil dihapus.',
], 200);
} catch (ModelNotFoundException $e) {
return response()->json([
'message' => 'Produk tidak ditemukan.',
], 404);
// } catch (ModelNotFoundException $e) {
// return response()->json([
// 'message' => 'Produk tidak ditemukan.',
// ], 404);
} catch (\PDOException $e) {
return response()->json([
'message' => 'Terjadi kesalahan pada koneksi database.',
Expand Down
5 changes: 2 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use App\Http\Controllers\ProdukController;
use App\Http\Controllers\DetailKonsultasiController;
use App\Http\Controllers\PembelianProdukController;
use App\Http\Controllers\DetailPembelianProdukController;
use App\Http\Controllers\Api\TreatmentController;
use App\Http\Controllers\Api\JenisTreatmentController;
use App\Http\Controllers\Api\BookingTreatmentController;
Expand Down Expand Up @@ -108,8 +107,8 @@
// Products Purchase Management
Route::prefix('products-purchase')->group(function () {
Route::post('/pembelian', [PembelianProdukController::class, 'store']); // Create new purchase
Route::get('/pembelian', [DetailPembelianProdukController::class, 'index']); // Get all purchases
Route::get('/pembelian/{id}', [DetailPembelianProdukController::class, 'show']); // Get purchase details by ID
Route::get('/pembelian', [PembelianProdukController::class, 'index']); // Get all purchases
Route::get('/pembelian/{id}', [PembelianProdukController::class, 'show']); // Get purchase details by ID
Route::put('/pembelian/{id}', [PembelianProdukController::class, 'update']); // Edit the tb_pembelian purchase
Route::delete('/pembelian/{id}', [PembelianProdukController::class, 'destroy']); // Delete purchase
});
Expand Down

0 comments on commit cacbce3

Please sign in to comment.