Skip to content

Commit

Permalink
refactor: update stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 14, 2023
1 parent d98bc35 commit fdd36c2
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 23 deletions.
15 changes: 10 additions & 5 deletions Generator/Stubs/controllers/api/crud.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Containers\{{section-name}}\{{container-name}}\UI\{{user-interface}}\Controllers;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use Apiato\Core\Exceptions\IncorrectIdException;
use Apiato\Core\Exceptions\InvalidTransformerException;
use App\Containers\{{section-name}}\{{container-name}}\Actions\Create{{model}}Action;
use App\Containers\{{section-name}}\{{container-name}}\Actions\Delete{{model}}Action;
Expand All @@ -26,17 +27,18 @@ use Prettus\Repository\Exceptions\RepositoryException;
class {{class-name}} extends {{base-controller}}
{
public function __construct(
private readonly Create{{model}}Action $create{{model}}Action
private readonly Update{{model}}Action $update{{model}}Action
private readonly Find{{model}}ByIdAction $find{{model}}ByIdAction
private readonly List{{models}}Action $list{{models}}Action
private readonly Delete{{model}}Action $delete{{model}}Action
private readonly Create{{model}}Action $create{{model}}Action,
private readonly Update{{model}}Action $update{{model}}Action,
private readonly Find{{model}}ByIdAction $find{{model}}ByIdAction,
private readonly List{{models}}Action $list{{models}}Action,
private readonly Delete{{model}}Action $delete{{model}}Action,
) {
}

/**
* @throws InvalidTransformerException
* @throws CreateResourceFailedException
* @throws IncorrectIdException
*/
public function create{{model}}(Create{{model}}Request $request): JsonResponse
{
Expand Down Expand Up @@ -69,7 +71,9 @@ class {{class-name}} extends {{base-controller}}
}

/**
* @throws IncorrectIdException
* @throws InvalidTransformerException
* @throws NotFoundException
* @throws UpdateResourceFailedException
*/
public function update{{model}}(Update{{model}}Request $request): array
Expand All @@ -81,6 +85,7 @@ class {{class-name}} extends {{base-controller}}

/**
* @throws DeleteResourceFailedException
* @throws NotFoundException
*/
public function delete{{model}}(Delete{{model}}Request $request): JsonResponse
{
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Repositories\{{model
use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;

class {{class-name}} extends ParentTask
{
Expand All @@ -22,7 +21,7 @@ class {{class-name}} extends ParentTask
{
try {
return $this->repository->create($data);
} catch (Exception) {
} catch (\Exception) {
throw new CreateResourceFailedException();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Repositories\{{model
use App\Ship\Exceptions\DeleteResourceFailedException;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class {{class-name}} extends ParentTask
Expand All @@ -26,7 +25,7 @@ class {{class-name}} extends ParentTask
return $this->repository->delete($id);
} catch (ModelNotFoundException) {
throw new NotFoundException();
} catch (Exception) {
} catch (\Exception) {
throw new DeleteResourceFailedException();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/find.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Data\Repositories\{{model
use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;

class {{class-name}} extends ParentTask
{
Expand All @@ -22,7 +21,7 @@ class {{class-name}} extends ParentTask
{
try {
return $this->repository->find($id);
} catch (Exception) {
} catch (\Exception) {
throw new NotFoundException();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/list.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class {{class-name}} extends ParentTask
*/
public function run(): mixed
{
return $this->addRequestCriteria()->repository->paginate();
return $this->repository->addRequestCriteria()->paginate();
}
}
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/update.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class {{class-name}} extends ParentTask
Expand All @@ -27,7 +26,7 @@ class {{class-name}} extends ParentTask
return $this->repository->update($data, $id);
} catch (ModelNotFoundException) {
throw new NotFoundException();
} catch (Exception) {
} catch (\Exception) {
throw new UpdateResourceFailedException();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/with_event/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}};
use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;

class {{class-name}} extends ParentTask
{
Expand All @@ -26,7 +25,7 @@ class {{class-name}} extends ParentTask
{{event}}::dispatch(${{_model}});

return ${{_model}};
} catch (Exception) {
} catch (\Exception) {
throw new CreateResourceFailedException();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/with_event/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}};
use App\Ship\Exceptions\DeleteResourceFailedException;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class {{class-name}} extends ParentTask
Expand All @@ -30,7 +29,7 @@ class {{class-name}} extends ParentTask
return $result;
} catch (ModelNotFoundException) {
throw new NotFoundException();
} catch (Exception) {
} catch (\Exception) {
throw new DeleteResourceFailedException();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/with_event/find.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Events\{{event}};
use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;

class {{class-name}} extends ParentTask
{
Expand All @@ -26,7 +25,7 @@ class {{class-name}} extends ParentTask
{{event}}::dispatch(${{_model}});

return ${{_model}};
} catch (Exception) {
} catch (\Exception) {
throw new NotFoundException();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/with_event/list.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class {{class-name}} extends ParentTask
*/
public function run(): mixed
{
$result = $this->addRequestCriteria()->repository->paginate();
$result = $this->repository->addRequestCriteria()->paginate();
{{event}}::dispatch($result);

return $result;
Expand Down
3 changes: 1 addition & 2 deletions Generator/Stubs/tasks/with_event/update.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use App\Containers\{{section-name}}\{{container-name}}\Models\{{model}};
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Tasks\Task as ParentTask;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class {{class-name}} extends ParentTask
Expand All @@ -31,7 +30,7 @@ class {{class-name}} extends ParentTask
return ${{_model}};
} catch (ModelNotFoundException) {
throw new NotFoundException();
} catch (Exception) {
} catch (\Exception) {
throw new UpdateResourceFailedException();
}
}
Expand Down

0 comments on commit fdd36c2

Please sign in to comment.