Skip to content

Commit

Permalink
correctly transform eggs that use inheritance (application api) (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 authored May 26, 2024
1 parent 73babfa commit e715e92
Showing 1 changed file with 12 additions and 53 deletions.
65 changes: 12 additions & 53 deletions app/Transformers/Api/Application/EggTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Arr;
use App\Models\Egg;
use App\Models\Server;
use League\Fractal\Resource\Item;
use App\Models\EggVariable;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\NullResource;
Expand Down Expand Up @@ -39,7 +38,11 @@ public function getResourceName(): string
*/
public function transform(Egg $model): array
{
$files = json_decode($model->config_files, true, 512, JSON_THROW_ON_ERROR);
$model->loadMissing('configFrom');

$files = json_decode($model->inherit_config_files, true, 512, JSON_THROW_ON_ERROR);

$model->loadMissing('scriptFrom');

return [
'id' => $model->id,
Expand All @@ -54,18 +57,18 @@ public function transform(Egg $model): array
'docker_images' => $model->docker_images,
'config' => [
'files' => $files,
'startup' => json_decode($model->config_startup, true),
'stop' => $model->config_stop,
'logs' => json_decode($model->config_logs, true),
'file_denylist' => $model->file_denylist,
'startup' => json_decode($model->inherit_config_startup, true),
'stop' => $model->inherit_config_stop,
'logs' => json_decode($model->inherit_config_logs, true),
'file_denylist' => $model->inherit_file_denylist,
'extends' => $model->config_from,
],
'startup' => $model->startup,
'script' => [
'privileged' => $model->script_is_privileged,
'install' => $model->script_install,
'entry' => $model->script_entry,
'container' => $model->script_container,
'install' => $model->copy_script_install,
'entry' => $model->copy_script_entry,
'container' => $model->copy_script_container,
'extends' => $model->copy_script_from,
],
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
Expand All @@ -89,50 +92,6 @@ public function includeServers(Egg $model): Collection|NullResource
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
}

/**
* Include more detailed information about the configuration if this Egg is
* extending another.
*/
public function includeConfig(Egg $model): Item|NullResource
{
if (is_null($model->config_from)) {
return $this->null();
}

$model->loadMissing('configFrom');

return $this->item($model, function (Egg $model) {
return [
'files' => json_decode($model->inherit_config_files),
'startup' => json_decode($model->inherit_config_startup),
'stop' => $model->inherit_config_stop,
'logs' => json_decode($model->inherit_config_logs),
];
});
}

/**
* Include more detailed information about the script configuration if the
* Egg is extending another.
*/
public function includeScript(Egg $model): Item|NullResource
{
if (is_null($model->copy_script_from)) {
return $this->null();
}

$model->loadMissing('scriptFrom');

return $this->item($model, function (Egg $model) {
return [
'privileged' => $model->script_is_privileged,
'install' => $model->copy_script_install,
'entry' => $model->copy_script_entry,
'container' => $model->copy_script_container,
];
});
}

/**
* Include the variables that are defined for this Egg.
*
Expand Down

0 comments on commit e715e92

Please sign in to comment.