diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php new file mode 100644 index 0000000..c394c24 --- /dev/null +++ b/app/Http/Controllers/OrganizationController.php @@ -0,0 +1,22 @@ +with('riskCategories') + ->with('activityCounties') + ->with('expertises') + ->with('resourceTypes') + ->with('volunteers') + ->get() + ); + } +} diff --git a/app/Http/Controllers/ResourceController.php b/app/Http/Controllers/ResourceController.php new file mode 100644 index 0000000..2cb9f63 --- /dev/null +++ b/app/Http/Controllers/ResourceController.php @@ -0,0 +1,23 @@ +with('county') + ->with('organisation') + ->with('category') + ->with('subcategory') + ->with('types') + ->get() + ); + } + +} diff --git a/app/Http/Resources/IdAndNameResource.php b/app/Http/Resources/IdAndNameResource.php new file mode 100644 index 0000000..cc80aa9 --- /dev/null +++ b/app/Http/Resources/IdAndNameResource.php @@ -0,0 +1,22 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name + ]; + } +} diff --git a/app/Http/Resources/OrganizationResource.php b/app/Http/Resources/OrganizationResource.php new file mode 100644 index 0000000..3bab5ea --- /dev/null +++ b/app/Http/Resources/OrganizationResource.php @@ -0,0 +1,31 @@ + + */ + public function toArray(Request $request): array + { + return ['id' => $this->id, + 'name' => $this->name, + 'type' => $this->type, + 'status' => $this->status, + 'expertises_area' => IdAndNameResource::collection($this->expertises), + 'risc_category' => IdAndNameResource::collection($this->riskCategories), + 'action_type' => IdAndNameResource::collection($this->resourceTypes), + 'activity_area' => $this->area, + 'county' => IdAndNameResource::collection($this->activityCounties), + 'created_at' => $this->created_at->format("Y-m-d H:i:s"), + 'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), + 'volunteers_count' => $this->volunteers->count(), + ]; + } +} diff --git a/app/Http/Resources/ResourceResource.php b/app/Http/Resources/ResourceResource.php new file mode 100644 index 0000000..3975f7e --- /dev/null +++ b/app/Http/Resources/ResourceResource.php @@ -0,0 +1,29 @@ + + */ + public function toArray(Request $request): array + { + return ['id' => $this->id, + 'name' => $this->name, + 'county' => IdAndNameResource::make($this->county), + 'organization' => IdAndNameResource::make($this->organisation), + 'category' => IdAndNameResource::make($this->category), + 'subcategory' => IdAndNameResource::make($this->subcategory), +// 'types' => IdAndNameResource::collection($this->types), + 'created_at' => $this->created_at->format("Y-m-d H:i:s"), + 'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), + ]; + + } +} diff --git a/config/filament-breezy.php b/config/filament-breezy.php index 382bf0d..2189153 100644 --- a/config/filament-breezy.php +++ b/config/filament-breezy.php @@ -112,7 +112,7 @@ |-------------------------------------------------------------------------- | Enable sanctum api token management. */ - 'enable_sanctum' => false, + 'enable_sanctum' => true, /* |-------------------------------------------------------------------------- | Sanctum permissions diff --git a/routes/api.php b/routes/api.php index 21e4de1..4e08d2f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use App\Http\Controllers\OrganizationController; +use App\Http\Controllers\ResourceController; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; @@ -15,6 +17,12 @@ | is assigned the "api" middleware group. Enjoy building your API! | */ +Route::middleware('auth:sanctum') + ->prefix('/v1') + ->group(function () { + Route::get('/organizations', OrganizationController::class); + Route::get('/resources', ResourceController::class); + }); Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user();