2024-03-07 10:35:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Project;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2024-07-01 14:26:50 +00:00
|
|
|
class ResourcesController extends Controller
|
2024-03-07 10:35:00 +00:00
|
|
|
{
|
|
|
|
public function resources(Request $request)
|
|
|
|
{
|
2024-07-01 14:26:50 +00:00
|
|
|
$teamId = getTeamIdFromToken();
|
2024-03-07 10:35:00 +00:00
|
|
|
if (is_null($teamId)) {
|
2024-07-01 14:26:50 +00:00
|
|
|
return invalidTokenResponse();
|
2024-03-07 10:35:00 +00:00
|
|
|
}
|
|
|
|
$projects = Project::where('team_id', $teamId)->get();
|
|
|
|
$resources = collect();
|
|
|
|
$resources->push($projects->pluck('applications')->flatten());
|
|
|
|
$resources->push($projects->pluck('services')->flatten());
|
2024-03-07 10:37:56 +00:00
|
|
|
foreach (collect(DATABASE_TYPES) as $db) {
|
|
|
|
$resources->push($projects->pluck(str($db)->plural(2))->flatten());
|
|
|
|
}
|
2024-03-07 10:35:00 +00:00
|
|
|
$resources = $resources->flatten();
|
2024-03-08 14:16:58 +00:00
|
|
|
$resources = $resources->map(function ($resource) {
|
|
|
|
$payload = $resource->toArray();
|
|
|
|
if ($resource->getMorphClass() === 'App\Models\Service') {
|
|
|
|
$payload['status'] = $resource->status();
|
|
|
|
} else {
|
|
|
|
$payload['status'] = $resource->status;
|
|
|
|
}
|
|
|
|
$payload['type'] = $resource->type();
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-08 14:16:58 +00:00
|
|
|
return $payload;
|
|
|
|
});
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-07-01 14:26:50 +00:00
|
|
|
return response()->json([
|
|
|
|
'success' => true,
|
|
|
|
'data' => serializeApiResponse($resources),
|
|
|
|
]);
|
2024-03-07 10:35:00 +00:00
|
|
|
}
|
|
|
|
}
|