Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.fr.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Arch CLI (nosleepman/module)
# Arch CLI (nosleepman1/arch-cli)

Un package Laravel pour générer une architecture backend complète à partir de modèles métier.
Ce package fournit des commandes artisan pour générer rapidement Modèles, Migrations, Contrôleurs, Services, Repositories, Policies, Événements, Écouteurs, Notifications et Ressources avec une seule commande.
Expand All @@ -15,7 +15,7 @@ Veuillez consulter les guides détaillés pour des instructions d'utilisation co

Installez le package via composer :
```bash
composer require nosleepman/module
composer require nosleepman1/arch-cli
```

Le "service provider" sera enregistré automatiquement.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Arch CLI (nosleepman/module)
# Arch CLI (nosleepman1/arch-cli)

A Laravel package to generate a complete backend architecture from business models.
This package provides artisan commands to scaffold Models, Migrations, Controllers, Services, Repositories, Policies, Events, Listeners, Notifications, and Resources with a single command.
Expand All @@ -15,7 +15,7 @@ Please refer to the detailed guides for complete usage instructions:

Require the package via composer:
```bash
composer require nosleepman/module
composer require nosleepman1/arch-cli
```

The service provider will be automatically registered.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nosleepman/module",
"name": "nosleepman1/arch-cli",
"replace": {
"nosleepman/arch-cli": "self.version"
"nosleepman1/arch-cli": "self.version"
},
"description": "A Laravel package to generate complete backend architecture from business models",
"type": "library",
Expand Down
1 change: 1 addition & 0 deletions src/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function generate(string $name, string $version, bool $withService): void
$stub = $this->getStubContent($stubFile);

$stub = str_replace('{{class}}', $name, $stub);
$stub = str_replace('{{pluralClass}}', \Illuminate\Support\Str::plural($name), $stub);
$stub = str_replace('{{VERSION}}', strtoupper($version), $stub);

$path = app_path('Http/Controllers/Api/' . strtoupper($version) . '/' . $name . 'Controller.php');
Expand Down
5 changes: 4 additions & 1 deletion src/Generators/RequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
class RequestGenerator
{
private $fields;
private $name;

public function generate($name, $fields = '')
{
$this->fields = $fields;
$this->name = $name;
$this->generateStoreRequest($name);
$this->generateUpdateRequest($name);
}
Expand Down Expand Up @@ -57,6 +59,7 @@ private function generateRules($fields)
{
$fieldList = explode(',', $fields);
$rules = '';
$tableName = strtolower($this->name) . 's';

foreach ($fieldList as $field) {
$parts = explode(':', trim($field));
Expand All @@ -78,7 +81,7 @@ private function generateRules($fields)

foreach ($modifiers as $mod) {
if ($mod === 'unique') {
$rule .= "|unique:{$fieldName}s";
$rule .= "|unique:{$tableName},{$fieldName}";
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Generators/ServiceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function generate(string $name, bool $withEvents = false, bool $withRepos

$ServiceStub = str_replace('{{class}}', $name, $ServiceStub);
$ServiceStub = str_replace('{{model}}', $name, $ServiceStub);
$ServiceStub = str_replace('{{pluralClass}}', \Illuminate\Support\Str::plural($name), $ServiceStub);

if ($withEvents) {
$ServiceStub = str_replace('{{use_events}}', 'use App\Events\\' . $name . 'Created;', $ServiceStub);
Expand Down
2 changes: 1 addition & 1 deletion src/Stubs/Controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class {{class}}Controller extends Controller

public function index(): JsonResponse
{
return response()->json({{class}}Resource::collection($this->service->get{{class}}es()));
return response()->json({{class}}Resource::collection($this->service->get{{pluralClass}}()));
}

public function show(int $id): JsonResponse
Expand Down
2 changes: 1 addition & 1 deletion src/Stubs/Service.stub
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class {{class}}Service
return $model;
}

public function get{{class}}es()
public function get{{pluralClass}}()
{
return {{model}}::all();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stubs/ServiceWithRepository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class {{class}}Service
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function get{{class}}es()
public function get{{pluralClass}}()
{
return $this->repository->all();
}
Expand Down
6 changes: 4 additions & 2 deletions tests/GenerateModuleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,26 @@ public function test_it_generates_complete_module_with_service_and_repository()
$this->assertStringContainsString('$this->repository->create($data)', $serviceContent);
$this->assertStringContainsString('use App\Events\ProductCreated;', $serviceContent);
$this->assertStringContainsString('event(new ProductCreated($model));', $serviceContent);
$this->assertStringContainsString('public function getProducts()', $serviceContent);

// Assert Controller
$controllerPath = app_path('Http/Controllers/Api/V1/ProductController.php');
$this->assertTrue(File::exists($controllerPath));
$controllerContent = File::get($controllerPath);
$this->assertStringContainsString('protected ProductService $service', $controllerContent);
$this->assertStringContainsString('getProducts()', $controllerContent);

// Assert Form Requests and dynamic validation rules
$storeRequestPath = app_path('Http/Requests/Product/StoreProductRequest.php');
$this->assertTrue(File::exists($storeRequestPath));
$storeRequestContent = File::get($storeRequestPath);
$this->assertStringContainsString("'title' => 'required|string|max:255|unique:titles'", $storeRequestContent);
$this->assertStringContainsString("'title' => 'required|string|max:255|unique:products,title'", $storeRequestContent);
$this->assertStringContainsString("'price' => 'required|integer'", $storeRequestContent);

$updateRequestPath = app_path('Http/Requests/Product/UpdateProductRequest.php');
$this->assertTrue(File::exists($updateRequestPath));
$updateRequestContent = File::get($updateRequestPath);
$this->assertStringContainsString("'title' => 'required|string|max:255|unique:titles'", $updateRequestContent);
$this->assertStringContainsString("'title' => 'required|string|max:255|unique:products,title'", $updateRequestContent);

// Assert API Resource
$resourcePath = app_path('Http/Resources/ProductResource.php');
Expand Down
Loading