Support oft parent groups
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateParentGroup;
|
||||
|
||||
use App\Enumerations\ParticipantGroupType;
|
||||
use App\Models\ParentGroup;
|
||||
|
||||
class CreateParentGroupAction
|
||||
{
|
||||
public function __construct(private CreateParentGroupRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): CreateParentGroupResponse
|
||||
{
|
||||
$response = new CreateParentGroupResponse();
|
||||
|
||||
$name = trim($this->request->name);
|
||||
|
||||
if ($name === '') {
|
||||
$response->message = 'Bitte einen Namen angeben.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->parentGroup = ParentGroup::create([
|
||||
'name' => $name,
|
||||
'is_fallback' => false,
|
||||
]);
|
||||
|
||||
$response->success = true;
|
||||
$response->message = sprintf('%s „%s" wurde angelegt.', ParticipantGroupType::ParentGroup->label(), $name);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateParentGroup;
|
||||
|
||||
class CreateParentGroupRequest
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateParentGroup;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
|
||||
class CreateParentGroupResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
public string $message = '';
|
||||
public ?ParentGroup $parentGroup = null;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateTenant;
|
||||
|
||||
use App\Enumerations\ParticipantGroupType;
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Models\Tenant;
|
||||
@@ -16,10 +17,17 @@ class CreateTenantAction
|
||||
{
|
||||
$response = new CreateTenantResponse();
|
||||
|
||||
if ($this->request->parentGroup === null) {
|
||||
$response->message = sprintf('Bitte bei „%s" eine Auswahl treffen.', ParticipantGroupType::ParentGroup->label());
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'name' => $this->request->name,
|
||||
'slug' => $this->request->slug,
|
||||
'url' => $this->request->url,
|
||||
'parent_group_id' => $this->request->parentGroup->id,
|
||||
'email' => '',
|
||||
'email_finance' => '',
|
||||
'account_name' => '',
|
||||
@@ -46,7 +54,7 @@ class CreateTenantAction
|
||||
}
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Stamm wurde angelegt.';
|
||||
$response->message = sprintf('%s wurde angelegt.', ParticipantGroupType::LocalGroup->label());
|
||||
$response->slug = $tenant->slug;
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateTenant;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
|
||||
class CreateTenantRequest
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $slug,
|
||||
public string $url,
|
||||
/** Pflicht; null heißt, die übermittelte ID war unbekannt. */
|
||||
public ?ParentGroup $parentGroup,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\DeleteParentGroup;
|
||||
|
||||
class DeleteParentGroupAction
|
||||
{
|
||||
public function __construct(private DeleteParentGroupRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): DeleteParentGroupResponse
|
||||
{
|
||||
$response = new DeleteParentGroupResponse();
|
||||
|
||||
// Die Fallback-Gruppe nimmt Mandanten ohne Zuordnung auf und muss deshalb bestehen bleiben.
|
||||
if ($this->request->parentGroup->is_fallback) {
|
||||
$response->message = sprintf('„%s" kann nicht gelöscht werden.', $this->request->parentGroup->name);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($this->request->inUse) {
|
||||
$response->message = sprintf(
|
||||
'„%s" ist noch zugeordnet und kann deshalb nicht gelöscht werden.',
|
||||
$this->request->parentGroup->name,
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->request->parentGroup->delete();
|
||||
|
||||
$response->success = true;
|
||||
$response->message = sprintf('„%s" wurde gelöscht.', $this->request->parentGroup->name);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\DeleteParentGroup;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
|
||||
class DeleteParentGroupRequest
|
||||
{
|
||||
public function __construct(
|
||||
public ParentGroup $parentGroup,
|
||||
/** Ob die Gruppe noch von einem Mandanten oder einer Anmeldung verwendet wird. */
|
||||
public bool $inUse,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\DeleteParentGroup;
|
||||
|
||||
class DeleteParentGroupResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
public string $message = '';
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\RenameParentGroup;
|
||||
|
||||
class RenameParentGroupAction
|
||||
{
|
||||
public function __construct(private RenameParentGroupRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): RenameParentGroupResponse
|
||||
{
|
||||
$response = new RenameParentGroupResponse();
|
||||
|
||||
$name = trim($this->request->name);
|
||||
|
||||
if ($name === '') {
|
||||
$response->message = 'Bitte einen Namen angeben.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Umbenennen ist jederzeit möglich: Mandanten und Anmeldungen verweisen über die ID.
|
||||
$this->request->parentGroup->update(['name' => $name]);
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Der Name wurde gespeichert.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\RenameParentGroup;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
|
||||
class RenameParentGroupRequest
|
||||
{
|
||||
public function __construct(
|
||||
public ParentGroup $parentGroup,
|
||||
public string $name,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\RenameParentGroup;
|
||||
|
||||
class RenameParentGroupResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
public string $message = '';
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateGlobalSettings;
|
||||
|
||||
use App\Models\GlobalSetting;
|
||||
|
||||
class UpdateGlobalSettingsAction
|
||||
{
|
||||
public function __construct(private UpdateGlobalSettingsRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): UpdateGlobalSettingsResponse
|
||||
{
|
||||
$response = new UpdateGlobalSettingsResponse();
|
||||
|
||||
$values = [
|
||||
GlobalSetting::LOCAL_GROUP_LABEL => trim($this->request->localGroupLabel),
|
||||
GlobalSetting::LOCAL_GROUP_LABEL_PLURAL => trim($this->request->localGroupLabelPlural),
|
||||
GlobalSetting::PARENT_GROUP_LABEL => trim($this->request->parentGroupLabel),
|
||||
GlobalSetting::PARENT_GROUP_LABEL_PLURAL => trim($this->request->parentGroupLabelPlural),
|
||||
];
|
||||
|
||||
// Eine leere Bezeichnung ließe Überschriften und Auswahlfelder ohne Beschriftung zurück.
|
||||
if (in_array('', $values, true)) {
|
||||
$response->message = 'Bitte alle Bezeichnungen ausfüllen.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->request->globalSettings->setMany($values);
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Einstellungen wurden gespeichert.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateGlobalSettings;
|
||||
|
||||
use App\Repositories\GlobalSettingRepository;
|
||||
|
||||
class UpdateGlobalSettingsRequest
|
||||
{
|
||||
public function __construct(
|
||||
public GlobalSettingRepository $globalSettings,
|
||||
public string $localGroupLabel,
|
||||
public string $localGroupLabelPlural,
|
||||
public string $parentGroupLabel,
|
||||
public string $parentGroupLabelPlural,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateGlobalSettings;
|
||||
|
||||
class UpdateGlobalSettingsResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
public string $message = '';
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateTenantGeneral;
|
||||
|
||||
use App\Enumerations\ParticipantGroupType;
|
||||
|
||||
class UpdateTenantGeneralAction
|
||||
{
|
||||
public function __construct(private UpdateTenantGeneralRequest $request)
|
||||
@@ -12,10 +14,17 @@ class UpdateTenantGeneralAction
|
||||
{
|
||||
$response = new UpdateTenantGeneralResponse();
|
||||
|
||||
if ($this->request->parentGroup === null) {
|
||||
$response->message = sprintf('Bitte bei „%s" eine Auswahl treffen.', ParticipantGroupType::ParentGroup->label());
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->request->tenant->update([
|
||||
'name' => $this->request->name,
|
||||
'slug' => $this->request->slug,
|
||||
'url' => $this->request->url,
|
||||
'parent_group_id' => $this->request->parentGroup->id,
|
||||
]);
|
||||
|
||||
$response->success = true;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateTenantGeneral;
|
||||
|
||||
use App\Models\ParentGroup;
|
||||
use App\Models\Tenant;
|
||||
|
||||
class UpdateTenantGeneralRequest
|
||||
@@ -11,6 +12,8 @@ class UpdateTenantGeneralRequest
|
||||
public string $name,
|
||||
public string $slug,
|
||||
public string $url,
|
||||
/** Pflicht; null heißt, die übermittelte ID war unbekannt. */
|
||||
public ?ParentGroup $parentGroup,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user