Move modules

This commit is contained in:
philipp lang 2024-10-24 23:17:23 +02:00
parent 3199a2d5fb
commit 494fc30d21
16 changed files with 19 additions and 138 deletions

View File

@ -2,7 +2,7 @@
namespace App\Maildispatcher\Models; namespace App\Maildispatcher\Models;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use Database\Factories\Maildispatcher\Models\MaildispatcherFactory; use Database\Factories\Maildispatcher\Models\MaildispatcherFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;

View File

@ -4,7 +4,7 @@ namespace App\Maildispatcher\Resources;
use App\Lib\HasMeta; use App\Lib\HasMeta;
use App\Maildispatcher\Models\Maildispatcher; use App\Maildispatcher\Models\Maildispatcher;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Resources\MailgatewayResource; use App\Mailgateway\Resources\MailgatewayResource;
use App\Member\FilterScope; use App\Member\FilterScope;
use App\Member\Member; use App\Member\Member;

View File

@ -1,27 +0,0 @@
<?php
namespace App\Mailgateway\Actions;
use App\Mailgateway\Models\Mailgateway;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class StoreAction
{
use AsAction;
use ValidatesRequests;
/**
* @param array<string, mixed> $input
*/
public function handle(array $input): void
{
$this->checkIfWorks($input);
Mailgateway::create($input);
}
public function asController(ActionRequest $request): void
{
$this->handle($request->validated());
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace App\Mailgateway\Actions;
use App\Mailgateway\Models\Mailgateway;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class UpdateAction
{
use AsAction;
use ValidatesRequests;
/**
* @param array<string, mixed> $input
*/
public function handle(Mailgateway $mailgateway, array $input): void
{
$this->checkIfWorks($input);
$mailgateway->update($input);
}
public function asController(Mailgateway $mailgateway, ActionRequest $request): void
{
$this->handle($mailgateway, $request->validated());
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Mailgateway\Actions;
use App\Mailgateway\Types\Type;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
trait ValidatesRequests
{
/**
* @param array<string, mixed> $input
*/
public function checkIfWorks(array $input): void
{
if (!app(data_get($input, 'type.cls'))->setParams($input['type']['params'])->works()) {
throw ValidationException::withMessages(['connection' => 'Verbindung fehlgeschlagen.']);
}
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'domain' => 'required|string|max:255',
...$this->typeValidation(),
'type.params' => 'present|array',
...collect(request()->input('type.cls')::rules('storeValidator'))->mapWithKeys(fn ($rules, $key) => ["type.params.{$key}" => $rules]),
];
}
/**
* @return array<string, mixed>
*/
public function getValidationAttributes(): array
{
return [
'type.cls' => 'Typ',
'name' => 'Beschreibung',
'domain' => 'Domain',
...collect(request()->input('type.cls')::fieldNames())->mapWithKeys(fn ($attribute, $key) => ["type.params.{$key}" => $attribute]),
];
}
/**
* @return array<string, mixed>
*/
private function typeValidation(): array
{
return [
'type.cls' => ['required', 'string', 'max:255', Rule::in(app('mail-gateways'))],
];
}
public function prepareForValidation(ActionRequest $request): void
{
if (!is_subclass_of(request()->input('type.cls'), Type::class)) {
throw ValidationException::withMessages(['type.cls' => 'Typ ist nicht valide.']);
}
}
}

View File

@ -2,7 +2,7 @@
namespace App\Mailgateway; namespace App\Mailgateway;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Resources\MailgatewayResource; use App\Mailgateway\Resources\MailgatewayResource;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;

View File

@ -3,7 +3,7 @@
namespace App\Mailgateway\Resources; namespace App\Mailgateway\Resources;
use App\Lib\HasMeta; use App\Lib\HasMeta;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\JsonResource;
/** /**

View File

@ -2,7 +2,7 @@
namespace Modules\Mailgateway\Components; namespace Modules\Mailgateway\Components;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\Type; use App\Mailgateway\Types\Type;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;

View File

@ -2,7 +2,7 @@
namespace Modules\Mailgateway\Components; namespace Modules\Mailgateway\Components;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use Livewire\Component; use Livewire\Component;
use Modules\Mailgateway\MailgatewaySettings; use Modules\Mailgateway\MailgatewaySettings;

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Tests\Feature\Mailgateway; namespace Modules\Mailgateway;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Livewire\Livewire; use Livewire\Livewire;

View File

@ -1,15 +1,17 @@
<?php <?php
namespace App\Mailgateway\Models; namespace Modules\Mailgateway\Models;
use App\Mailgateway\Types\Type; use App\Mailgateway\Types\Type;
use Database\Factories\Mailgateway\Models\MailgatewayFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Mailgateway extends Model class Mailgateway extends Model
{ {
public static $factory = MailgatewayFactory::class;
/** @use HasFactory<MailgatewayFactory> */ /** @use HasFactory<MailgatewayFactory> */
use HasFactory; use HasFactory;
use HasUuids; use HasUuids;

View File

@ -1,14 +1,13 @@
<?php <?php
namespace Database\Factories\Mailgateway\Models; namespace Modules\Mailgateway\Models;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use App\Mailgateway\Types\Type; use App\Mailgateway\Types\Type;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/** /**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Mailgateway\Models\Mailgateway> * @extends Factory<Mailgateway>
*/ */
class MailgatewayFactory extends Factory class MailgatewayFactory extends Factory
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\Feature\Mailgateway; namespace Modules\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use App\Mailgateway\Types\MailmanType; use App\Mailgateway\Types\MailmanType;

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Tests\Feature\Mailgateway; namespace Modules\Mailgateway;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use App\Mailgateway\Types\MailmanType; use App\Mailgateway\Types\MailmanType;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;

View File

@ -6,7 +6,7 @@ use \Mockery as M;
use App\Activity; use App\Activity;
use App\Maildispatcher\Models\Localmaildispatcher; use App\Maildispatcher\Models\Localmaildispatcher;
use App\Maildispatcher\Models\Maildispatcher; use App\Maildispatcher\Models\Maildispatcher;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use App\Member\Member; use App\Member\Member;
use App\Member\Membership; use App\Member\Membership;

View File

@ -4,7 +4,7 @@ namespace Tests\EndToEnd\Maildispatcher;
use App\Maildispatcher\Actions\ResyncAction; use App\Maildispatcher\Actions\ResyncAction;
use App\Maildispatcher\Models\Maildispatcher; use App\Maildispatcher\Models\Maildispatcher;
use App\Mailgateway\Models\Mailgateway; use Modules\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType; use App\Mailgateway\Types\LocalType;
use App\Member\FilterScope; use App\Member\FilterScope;
use App\Member\Member; use App\Member\Member;