big update base struktur tahap 1
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\File;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StoredFileResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'tenant_id' => $this->tenant_id,
|
||||
'original_name' => $this->original_name,
|
||||
'extension' => $this->extension,
|
||||
'mime_type' => $this->mime_type,
|
||||
'size' => $this->size,
|
||||
'category' => $this->category,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\MenuGroup;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MenuGroupResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'tenant_id' => $this->tenant_id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'is_system' => (bool) $this->is_system,
|
||||
'is_active' => (bool) $this->is_active,
|
||||
'tenant' => $this->whenLoaded('tenant', fn () => $this->tenant ? [
|
||||
'id' => $this->tenant->id,
|
||||
'tenant_code' => $this->tenant->tenant_code,
|
||||
'tenant_name' => $this->tenant->tenant_name,
|
||||
] : null),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\MenuList;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MenuListResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'parent_id' => $this->parent_id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'url' => $this->url,
|
||||
'icon' => $this->icon,
|
||||
'component' => $this->component,
|
||||
'sort_order' => $this->sort_order,
|
||||
'is_active' => $this->is_active,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Nas;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class NasResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = $this->resource->attributesToArray();
|
||||
unset($data['api_password'], $data['radius_secret'], $data['community'], $data['auth_password'], $data['privacy_password'], $data['password']);
|
||||
|
||||
$data['tenant'] = $this->whenLoaded('tenant', fn () => [
|
||||
'id' => $this->tenant->id,
|
||||
'tenant_code' => $this->tenant->tenant_code,
|
||||
'tenant_name' => $this->tenant->tenant_name,
|
||||
]);
|
||||
|
||||
foreach ([
|
||||
'api_password' => 'has_api_password',
|
||||
'radius_secret' => 'has_radius_secret',
|
||||
'community' => 'has_community',
|
||||
'auth_password' => 'has_auth_password',
|
||||
'privacy_password' => 'has_privacy_password',
|
||||
'password' => 'has_password',
|
||||
] as $column => $flag) {
|
||||
if (array_key_exists($column, $this->resource->getAttributes())) {
|
||||
$data[$flag] = filled($this->resource->getRawOriginal($column));
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Tenant;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TenantResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'tenant_code' => $this->tenant_code,
|
||||
'tenant_name' => $this->tenant_name,
|
||||
'phone' => $this->phone,
|
||||
'email' => $this->email,
|
||||
'address' => $this->address,
|
||||
'status' => $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\User;
|
||||
|
||||
use App\Http\Resources\File\StoredFileResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'username' => $this->username,
|
||||
'email' => $this->email,
|
||||
'whatsapp_number' => $this->whatsapp_number,
|
||||
'profile_photo' => $this->whenLoaded(
|
||||
'profilePhoto',
|
||||
fn () => $this->profilePhoto ? new StoredFileResource($this->profilePhoto) : null
|
||||
),
|
||||
'is_master' => (bool) $this->is_master,
|
||||
'access_level' => $this->access_level->value,
|
||||
'status' => $this->status,
|
||||
'verification_channel' => $this->verification_channel,
|
||||
'verification_target' => $this->verification_target,
|
||||
'verified_at' => $this->verified_at,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
|
||||
'user_profile' => $this->whenLoaded('userProfile', function () {
|
||||
return $this->userProfile ? [
|
||||
'id' => $this->userProfile->id,
|
||||
'user_id' => $this->userProfile->user_id,
|
||||
'nik' => $this->userProfile->nik,
|
||||
'address' => $this->userProfile->address,
|
||||
'provinsi_id' => $this->userProfile->provinsi_id,
|
||||
'kabupaten_id' => $this->userProfile->kabupaten_id,
|
||||
'kecamatan_id' => $this->userProfile->kecamatan_id,
|
||||
'desa_id' => $this->userProfile->desa_id,
|
||||
'created_at' => $this->userProfile->created_at,
|
||||
'updated_at' => $this->userProfile->updated_at,
|
||||
] : null;
|
||||
}),
|
||||
|
||||
'user_tenants' => $this->whenLoaded('userTenants', function () {
|
||||
return $this->userTenants->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'user_id' => $item->user_id,
|
||||
'tenant_id' => $item->tenant_id,
|
||||
'is_default' => (bool) $item->is_default,
|
||||
'created_at' => $item->created_at,
|
||||
'updated_at' => $item->updated_at,
|
||||
'tenant' => $item->relationLoaded('tenant') && $item->tenant ? [
|
||||
'id' => $item->tenant->id,
|
||||
'tenant_code' => $item->tenant->tenant_code ?? null,
|
||||
'tenant_name' => $item->tenant->tenant_name ?? null,
|
||||
] : null,
|
||||
];
|
||||
})->values();
|
||||
}),
|
||||
|
||||
'user_menu_groups' => $this->whenLoaded('userMenuGroups', function () {
|
||||
return $this->userMenuGroups->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'user_id' => $item->user_id,
|
||||
'menu_group_id' => $item->menu_group_id,
|
||||
'tenant_id' => $item->tenant_id,
|
||||
'created_at' => $item->created_at,
|
||||
'updated_at' => $item->updated_at,
|
||||
'menu_group' => $item->relationLoaded('menuGroup') && $item->menuGroup ? [
|
||||
'id' => $item->menuGroup->id,
|
||||
'name' => $item->menuGroup->name ?? null,
|
||||
'menu_group_name' => $item->menuGroup->menu_group_name ?? null,
|
||||
] : null,
|
||||
'tenant' => $item->relationLoaded('tenant') && $item->tenant ? [
|
||||
'id' => $item->tenant->id,
|
||||
'tenant_code' => $item->tenant->tenant_code ?? null,
|
||||
'tenant_name' => $item->tenant->tenant_name ?? null,
|
||||
] : null,
|
||||
];
|
||||
})->values();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Wilayah;
|
||||
|
||||
use App\Models\WilayahDesa;
|
||||
use App\Models\WilayahKabupaten;
|
||||
use App\Models\WilayahKecamatan;
|
||||
use App\Models\WilayahProvinsi;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WilayahResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'kode' => $this->kode,
|
||||
'nama' => $this->nama,
|
||||
'tingkat' => match (true) {
|
||||
$this->resource instanceof WilayahDesa => 'desa',
|
||||
$this->resource instanceof WilayahKecamatan => 'kecamatan',
|
||||
$this->resource instanceof WilayahKabupaten => 'kabupaten',
|
||||
$this->resource instanceof WilayahProvinsi => 'provinsi',
|
||||
},
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
|
||||
if ($this->resource instanceof WilayahKabupaten) {
|
||||
$data['provinsi_id'] = $this->provinsi_id;
|
||||
$data['provinsi'] = $this->whenLoaded('provinsi', fn () => $this->node($this->provinsi));
|
||||
}
|
||||
|
||||
if ($this->resource instanceof WilayahKecamatan) {
|
||||
$data['kabupaten_id'] = $this->kabupaten_id;
|
||||
$data['kabupaten'] = $this->whenLoaded('kabupaten', fn () => $this->node($this->kabupaten));
|
||||
$data['provinsi'] = $this->when(
|
||||
$this->relationLoaded('kabupaten') && $this->kabupaten?->relationLoaded('provinsi'),
|
||||
fn () => $this->node($this->kabupaten?->provinsi)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->resource instanceof WilayahDesa) {
|
||||
$data['kecamatan_id'] = $this->kecamatan_id;
|
||||
$data['kecamatan'] = $this->whenLoaded('kecamatan', fn () => $this->node($this->kecamatan));
|
||||
$data['kabupaten'] = $this->when(
|
||||
$this->relationLoaded('kecamatan') && $this->kecamatan?->relationLoaded('kabupaten'),
|
||||
fn () => $this->node($this->kecamatan?->kabupaten)
|
||||
);
|
||||
$data['provinsi'] = $this->when(
|
||||
$this->relationLoaded('kecamatan')
|
||||
&& $this->kecamatan?->relationLoaded('kabupaten')
|
||||
&& $this->kecamatan?->kabupaten?->relationLoaded('provinsi'),
|
||||
fn () => $this->node($this->kecamatan?->kabupaten?->provinsi)
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function node($wilayah): ?array
|
||||
{
|
||||
return $wilayah ? [
|
||||
'id' => $wilayah->id,
|
||||
'kode' => $wilayah->kode,
|
||||
'nama' => $wilayah->nama,
|
||||
] : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user