2018-02-27 21:28:43 -06:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Http\Controllers\Api\Client\Servers;
|
2018-02-27 21:28:43 -06:00
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
|
use App\Http\Requests\Api\Client\Servers\GetServerRequest;
|
2025-09-24 13:34:19 +02:00
|
|
|
use App\Models\Server;
|
|
|
|
|
use App\Services\Servers\GetUserPermissionsService;
|
|
|
|
|
use App\Transformers\Api\Client\ServerTransformer;
|
2025-02-26 16:12:19 +01:00
|
|
|
use Dedoc\Scramble\Attributes\Group;
|
2018-02-27 21:28:43 -06:00
|
|
|
|
2025-02-26 16:12:19 +01:00
|
|
|
#[Group('Server', weight: 0)]
|
2018-02-27 21:28:43 -06:00
|
|
|
class ServerController extends ClientApiController
|
|
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
public function __construct(private GetUserPermissionsService $permissionsService)
|
2020-03-22 16:56:00 -07:00
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 21:28:43 -06:00
|
|
|
/**
|
2025-02-26 16:12:19 +01:00
|
|
|
* View server
|
|
|
|
|
*
|
2025-03-03 14:41:19 -05:00
|
|
|
* Transform an individual server into a response that can be consumed by a client using the API.
|
|
|
|
|
*
|
|
|
|
|
* @return array<array-key, mixed>
|
2018-02-27 21:28:43 -06:00
|
|
|
*/
|
2019-09-05 21:41:20 -07:00
|
|
|
public function index(GetServerRequest $request, Server $server): array
|
2018-02-27 21:28:43 -06:00
|
|
|
{
|
2019-09-05 21:41:20 -07:00
|
|
|
return $this->fractal->item($server)
|
2018-02-27 21:28:43 -06:00
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
2020-03-22 16:56:00 -07:00
|
|
|
->addMeta([
|
|
|
|
|
'is_server_owner' => $request->user()->id === $server->owner_id,
|
2020-04-17 10:21:15 -07:00
|
|
|
'user_permissions' => $this->permissionsService->handle($server, $request->user()),
|
2020-03-22 16:56:00 -07:00
|
|
|
])
|
2018-02-27 21:28:43 -06:00
|
|
|
->toArray();
|
|
|
|
|
}
|
|
|
|
|
}
|