Browse Source

Update: Api assetStatusApi dan PeminjamanAPI

master
unknown 1 year ago
parent
commit
4b7a20d59a
  1. 23
      app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php
  2. 24
      app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php
  3. 16
      app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php
  4. 93
      app/Http/Controllers/API/v1/PetiApi/PetiApiController.php
  5. 2
      database/migrations/2023_10_23_075245_create_users_table.php
  6. 7
      routes/api.php

23
app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php

@ -1,23 +0,0 @@
<?php
namespace App\Http\Controllers\API\v1\AssetStatusApi;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AssetStatusApiController extends Controller
{
public function index()
{
$m_asset = \App\Models\Peti::with([
'warehouse',
'tipe_peti',
'customer'
])->get();
return ResponseFormatter::success([
'message' => 'Data asset berhasil diambil',
'asset' => $m_asset,
], 200);
}
}

24
app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php

@ -19,28 +19,20 @@ class PeminjamanApiController extends Controller
'warehouseEnter'
])->get();
// Menghapus atribut yang terkait dengan "enter"
foreach ($peminjaman as $peminjamanItem) {
unset($peminjamanItem->enter_at);
unset($peminjamanItem->enter_pic);
unset($peminjamanItem->enter_warehouse);
unset($peminjamanItem->kondisi_peti);
}
return ResponseFormatter::success([
'message' => 'Data peminjaman berhasil diambil',
'asset_status' => $peminjaman,
]);
}
// public function index()
// {
// $peminjaman = \App\Models\asset_status::with([
// 'peti.customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
// 'peti.tipe_peti:id,type,size_peti,description',
// 'warehouse',
// 'warehouseEnter'
// ])->paginate(10);
// return ResponseFormatter::success([
// 'message' => 'Data peminjaman berhasil diambil',
// 'asset_status' => $peminjaman,
// ]);
// }
public function getWarehouseEnter()
{
$warehouse = \App\Models\m_warehouse::get();

16
app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php

@ -8,7 +8,23 @@ use App\Http\Controllers\Controller;
class PengembalianBarangApiController extends Controller
{
public function index()
{
$peminjaman = \App\Models\asset_status::with([
'peti.customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'peti.tipe_peti:id,type,size_peti,description',
'warehouse',
'warehouseEnter'
])->get();
return ResponseFormatter::success([
'message' => 'Data peminjaman berhasil diambil',
'asset_status' => $peminjaman,
]);
}
public function create()
{
$pengembalian = \App\Models\asset_status::with([
'peti.customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',

93
app/Http/Controllers/API/v1/PetiApi/PetiApiController.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers\API\v1\PetiApi;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PetiApiController extends Controller
{
public function index()
{
$petis = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->get();
if (!$petis) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'petis' => $petis,
], 200);
}
public function show($id)
{
$peti = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'peti' => $peti,
], 200);
}
public function edit($id)
{
$peti = \App\Models\Peti::with([
'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address',
'tipe_peti:id,type,size_peti,description',
'warehouse:id,name,address',
])->find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
return ResponseFormatter::success([
'message' => 'Data peti berhasil diambil',
'petis' => $peti,
], 200);
}
public function update(Request $request, $id)
{
$peti = \App\Models\Peti::find($id);
if (!$peti) {
return ResponseFormatter::error([
'message' => 'Data peti tidak ditemukan',
], 'Data Not Found', 404);
}
// $peti->update($request->all());
$peti->update([
'warehouse_id' => $request->warehouse_id,
'updated_by' => $request->updated_by,
]);
return ResponseFormatter::success([
'message' => 'Data peti berhasil diupdate',
'petis' => $peti,
], 200);
}
}

2
database/migrations/2023_10_23_075245_create_users_table.php

@ -25,7 +25,7 @@ return new class extends Migration
$table->string('foto', 255)->nullable();
$table->string('jenis_kelamin', 20)->nullable();
$table->string('agama', 15)->nullable();
$table->foreignId('role_id')->constrained('m_roles')->onDelete('cascade');
$table->foreignId('role_id')->nullable()->constrained('m_roles')->onDelete('cascade')->nullable();
$table->bigInteger('warehouse_id')->unsigned()->nullable();
$table->foreign('warehouse_id')->references('id')->on('m_warehouses')->onDelete('set null');
$table->text('address')->nullable();

7
routes/api.php

@ -1,5 +1,6 @@
<?php
use App\Models\ContactInfo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@ -30,10 +31,14 @@ Route::prefix('v1')->group(function () {
Route::get('/asset-status/peminjaman/show/{id}', [App\Http\Controllers\API\v1\PeminjamanApi\PeminjamanApiController::class, 'show'])->name('peminjaman-barang.show');
Route::get('/asset-status/pengembalian', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'index'])->name('pengembalian-barang');
Route::get('/asset-status/pengembalian/create', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'create'])->name('pengembalian-barang.create');
Route::put('/asset-status/update/{id}', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'update'])->name('pengembalian-barang.update');
Route::get('/asset-status/pengembalian/show/{id}', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'show'])->name('pengembalian-barang.show');
Route::get('/peti-asset', [App\Http\Controllers\API\v1\AssetStatusApi\AssetStatusApiController::class, 'index'])->name('peti.barang');
Route::get('/peti-asset', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'index'])->name('peti.barang');
Route::get('/peti-asset/show/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'show'])->name('peti.barang.show');
Route::get('/peti-asset/edit/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'edit'])->name('peti.barang.edit');
Route::put('/peti-asset/update/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'update'])->name('peti.barang.update');
Route::get('/m-warehouse', [App\Http\Controllers\API\v1\WarehouseApi\WarehouseApiController::class, 'index'])->name('warehouse');
});

Loading…
Cancel
Save