Skip to content

Commit

Permalink
fix(generator): outdated generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 8, 2024
1 parent 654a42d commit ae78afa
Show file tree
Hide file tree
Showing 65 changed files with 196 additions and 397 deletions.
4 changes: 2 additions & 2 deletions src/Generator/Commands/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function getUserInputs(): array|null
$model = $this->containerName;
$models = Pluralizer::plural($model);

$entity = Str::lower($model);
$entities = Pluralizer::plural($entity);
$entity = Str::camel($model);
$entities = Str::of($entity)->pluralStudly()->camel()->toString();

return [
'path-parameters' => [
Expand Down
1 change: 1 addition & 0 deletions src/Generator/Commands/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function getUserInputs(): array|null
'--section' => $this->sectionName,
'--container' => $this->containerName,
'--file' => $this->fileName . 'Repository',
'--model' => $this->fileName,
]);

if (0 != $status) {
Expand Down
6 changes: 6 additions & 0 deletions src/Generator/Commands/RepositoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Apiato\Core\Generator\GeneratorCommand;
use Apiato\Core\Generator\Interfaces\ComponentsGenerator;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerator
{
Expand All @@ -13,6 +14,7 @@ class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerato
* This is a replacement of the `getArguments` function "which reads whenever it's called".
*/
public array $inputs = [
['model', null, InputOption::VALUE_OPTIONAL, 'The model to generate this Factory for'],
];
/**
* The console command name.
Expand Down Expand Up @@ -45,6 +47,8 @@ class RepositoryGenerator extends GeneratorCommand implements ComponentsGenerato

public function getUserInputs(): array|null
{
$model = $this->checkParameterOrAsk('model', 'Enter the name of the Model to generate this Repository for');

return [
'path-parameters' => [
'section-name' => $this->sectionName,
Expand All @@ -56,6 +60,8 @@ public function getUserInputs(): array|null
'_container-name' => Str::lower($this->containerName),
'container-name' => $this->containerName,
'class-name' => $this->fileName,
'model' => $model,
'_model' => Str::lower($model),
],
'file-parameters' => [
'file-name' => $this->fileName,
Expand Down
1 change: 1 addition & 0 deletions src/Generator/Commands/TaskGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function getUserInputs(): array|null
'model' => $model,
'models' => $models,
'_model' => Str::lower($model),
'model_' => Str::camel($model),
'event' => $event,
],
'file-parameters' => [
Expand Down
5 changes: 3 additions & 2 deletions src/Generator/Commands/TestUnitTestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getUserInputs(): array|null
$model = $this->option('model');
$stub = $this->option('stub');
$event = $this->option('event');
$tablename = $this->option('tablename');
$tableName = $this->option('tablename');

if ($stub) {
if ($event) {
Expand Down Expand Up @@ -90,7 +90,8 @@ public function getUserInputs(): array|null
'models' => $models,
'_models' => Str::lower($models),
'event' => $event,
'table-name' => $tablename,
'table-name' => $tableName,
'_table-name_' => Str::studly($tableName),
],
'file-parameters' => [
'file-name' => $this->fileName,
Expand Down
5 changes: 2 additions & 3 deletions src/Generator/Stubs/composer.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "apiato/{{_container-name}}",
"description": "{{container-name}} Container for apiato.",
"require": {
}
"description": "{{container-name}} Container",
"require": {}
}
9 changes: 2 additions & 7 deletions src/Generator/Stubs/controllers/api/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ use Illuminate\Http\JsonResponse;

class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly Create{{model}}Action $action,
) {
}

/**
* @throws CreateResourceFailedException
* @throws InvalidTransformerException
* @throws IncorrectIdException
*/
public function __invoke(Create{{model}}Request $request): JsonResponse
public function __invoke(Create{{model}}Request $request, Create{{model}}Action $action): JsonResponse
{
${{entity}} = $this->action->run($request);
${{entity}} = $action->run($request);

return $this->created($this->transform(${{entity}}, {{model}}Transformer::class));
}
Expand Down
34 changes: 17 additions & 17 deletions src/Generator/Stubs/controllers/api/crud.stub
Original file line number Diff line number Diff line change
Expand Up @@ -40,57 +40,57 @@ class {{class-name}} extends {{base-controller}}
* @throws CreateResourceFailedException
* @throws IncorrectIdException
*/
public function create{{model}}(Create{{model}}Request $request): JsonResponse
public function create{{model}}(Create{{model}}Request $request, Create{{model}}Action $action): JsonResponse
{
${{entity}} = $this->create{{model}}Action->run($request);
${{entity}} = $action->run($request);

return $this->created($this->transform(${{entity}}, {{model}}Transformer::class));
return $this->created($this->transform(${{entity}}, {{model}}Transformer::class));
}

/**
* @throws InvalidTransformerException
* @throws NotFoundException
*/
public function find{{model}}ById(Find{{model}}ByIdRequest $request): array
public function find{{model}}ById(Find{{model}}ByIdRequest $request, Find{{model}}ByIdAction $action): array
{
${{entity}} = $this->find{{model}}ByIdAction->run($request);
${{entity}} = $action->run($request);

return $this->transform(${{entity}}, {{model}}Transformer::class);
return $this->transform(${{entity}}, {{model}}Transformer::class);
}

/**
* @throws InvalidTransformerException
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function list{{models}}(List{{models}}Request $request): array
public function list{{models}}(List{{models}}Request $request, List{{models}}Action $action): array
{
${{entities}} = $this->list{{models}}Action->run($request);
${{entities}} = $action->run($request);

return $this->transform(${{entities}}, {{model}}Transformer::class);
return $this->transform(${{entities}}, {{model}}Transformer::class);
}

/**
* @throws IncorrectIdException
* @throws InvalidTransformerException
* @throws NotFoundException
* @throws UpdateResourceFailedException
* @throws IncorrectIdException
* @throws NotFoundException
*/
public function update{{model}}(Update{{model}}Request $request): array
public function update{{model}}(Update{{model}}Request $request, Update{{model}}Action $action): array
{
${{entity}} = $this->update{{model}}Action->run($request);
${{entity}} = $action->run($request);

return $this->transform(${{entity}}, {{model}}Transformer::class);
return $this->transform(${{entity}}, {{model}}Transformer::class);
}

/**
* @throws DeleteResourceFailedException
* @throws NotFoundException
*/
public function delete{{model}}(Delete{{model}}Request $request): JsonResponse
public function delete{{model}}(Delete{{model}}Request $request, Delete{{model}}Action $action): JsonResponse
{
$this->delete{{model}}Action->run($request);
$action->run($request);

return $this->noContent();
return $this->noContent();
}
}
9 changes: 2 additions & 7 deletions src/Generator/Stubs/controllers/api/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ use Illuminate\Http\JsonResponse;

class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly Delete{{model}}Action $action,
) {
}

/**
* @throws DeleteResourceFailedException
* @throws NotFoundException
*/
public function __invoke(Delete{{model}}Request $request): JsonResponse
public function __invoke(Delete{{model}}Request $request, Delete{{model}}Action $action): JsonResponse
{
$this->action->run($request);
$action->run($request);

return $this->noContent();
}
Expand Down
12 changes: 4 additions & 8 deletions src/Generator/Stubs/controllers/api/find.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ use App\Ship\Parents\Controllers\{{base-controller}};

class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly Find{{model}}ByIdAction $action
) {
}

/**
* @throws InvalidTransformerException|NotFoundException
* @throws InvalidTransformerException
* @throws NotFoundException
*/
public function __invoke(Find{{model}}ByIdRequest $request): array
public function __invoke(Find{{model}}ByIdRequest $request, Find{{model}}ByIdAction $action): array
{
${{entity}} = $this->action->run($request);
${{entity}} = $action->run($request);

return $this->transform(${{entity}}, {{model}}Transformer::class);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Generator/Stubs/controllers/api/list.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ use Prettus\Repository\Exceptions\RepositoryException;

class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly List{{models}}Action $action
) {
}

/**
* @throws InvalidTransformerException
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function __invoke(List{{models}}Request $request): array
public function __invoke(List{{models}}Request $request, List{{models}}Action $action): array
{
${{entities}} = $this->action->run($request);
${{entities}} = $action->run($request);

return $this->transform(${{entities}}, {{model}}Transformer::class);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Generator/Stubs/controllers/api/update.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@ use App\Ship\Parents\Controllers\{{base-controller}};

class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly Update{{model}}Action $action
) {
}

/**
* @throws InvalidTransformerException
* @throws UpdateResourceFailedException
* @throws IncorrectIdException
* @throws NotFoundException
*/
public function __invoke(Update{{model}}Request $request): array
public function __invoke(Update{{model}}Request $request, Update{{model}}Action $action): array
{
${{entity}} = $this->action->run($request);
${{entity}} = $action->run($request);

return $this->transform(${{entity}}, {{model}}Transformer::class);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Generator/Stubs/events/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace App\Containers\{{section-name}}\{{container-name}}\Events;

use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Parents\Events\Event as ParentEvent;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\PrivateChannel;

class {{class-name}} extends ParentEvent
{
public function __construct(
public readonly int $result,
public readonly bool $result,
) {
}

Expand Down
1 change: 0 additions & 1 deletion src/Generator/Stubs/events/list.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Containers\{{section-name}}\{{container-name}}\Events;

use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Parents\Events\Event as ParentEvent;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\PrivateChannel;
Expand Down
6 changes: 2 additions & 4 deletions src/Generator/Stubs/factory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Parents\Factories\Factory as ParentFactory;

/**
* @template TModel of {{class-name}}
* @template TModel of {{model}}
*
* @extends ParentFactory<TModel>
*/
Expand All @@ -17,8 +17,6 @@ class {{class-name}} extends ParentFactory

public function definition(): array
{
return [
//
];
return [];
}
}
4 changes: 1 addition & 3 deletions src/Generator/Stubs/migration.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
public function up(): void
{
Schema::create('{{table-name}}', function (Blueprint $table) {
Schema::create('{{table-name}}', static function (Blueprint $table) {
$table->id();

$table->timestamps();
// $table->softDeletes();
});
}

Expand Down
4 changes: 0 additions & 4 deletions src/Generator/Stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ use App\Ship\Parents\Models\Model as ParentModel;

class {{class-name}} extends ParentModel
{
/**
* A resource key to be used in the serialized responses.
*/
protected $resourceKey = '{{resource-key}}';
}
2 changes: 1 addition & 1 deletion src/Generator/Stubs/readme.stub
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Apiato {{container-name}} Container
### {{container-name}} Container

9 changes: 7 additions & 2 deletions src/Generator/Stubs/repository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

namespace App\Containers\{{section-name}}\{{container-name}}\Data\Repositories;

use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Parents\Repositories\Repository as ParentRepository;

/**
* @template TModel of {{model}}
*
* @extends ParentRepository<TModel>
*/
class {{class-name}} extends ParentRepository
{
protected $fieldSearchable = [
'id' => '=',
// ...
// 'id' => '=',
];
}
4 changes: 2 additions & 2 deletions src/Generator/Stubs/requests/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest;
class {{class-name}} extends ParentRequest
{
protected array $access = [
'permissions' => '',
'roles' => '',
'permissions' => null,
'roles' => null,
];

protected array $decode = [
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Stubs/requests/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest;
class {{class-name}} extends ParentRequest
{
protected array $access = [
'permissions' => '',
'roles' => '',
'permissions' => null,
'roles' => null,
];

protected array $decode = [
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Stubs/requests/edit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use App\Ship\Parents\Requests\Request as ParentRequest;
class {{class-name}} extends ParentRequest
{
protected array $access = [
'permissions' => '',
'roles' => '',
'permissions' => null,
'roles' => null,
];

protected array $decode = [
Expand Down
Loading

0 comments on commit ae78afa

Please sign in to comment.