Skip to content

Commit

Permalink
Merge pull request #1262 from cultuurnet/feature/PPF-463
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen authored Jul 16, 2024
2 parents 22dae54 + 946804a commit 07b888b
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 154 deletions.
22 changes: 19 additions & 3 deletions app/Domain/Integrations/Controllers/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Domain\Integrations\FormRequests\StoreIntegrationRequest;
use App\Domain\Integrations\FormRequests\StoreIntegrationUrlRequest;
use App\Domain\Integrations\FormRequests\UpdateContactInfoRequest;
use App\Domain\Integrations\FormRequests\UpdateIntegrationOrganizersRequest;
use App\Domain\Integrations\FormRequests\UpdateIntegrationRequest;
use App\Domain\Integrations\FormRequests\UpdateIntegrationUrlsRequest;
use App\Domain\Integrations\FormRequests\UpdateOrganizationRequest;
Expand Down Expand Up @@ -292,12 +293,27 @@ public function updateOrganization(string $id, UpdateOrganizationRequest $reques
);
}

public function updateOrganizers(string $integrationId, UpdateIntegrationOrganizersRequest $request): RedirectResponse
{
$integration = $this->integrationRepository->getById(Uuid::fromString($integrationId));

$organizerIds = collect($integration->organizers())->map(fn (Organizer $organizer) => $organizer->organizerId);
$newOrganizers = array_filter(
OrganizerMapper::mapUpdateOrganizers($request, $integrationId),
fn (Organizer $organizer) => !in_array($organizer->organizerId, $organizerIds->toArray(), true)
);

$this->organizerRepository->create(...$newOrganizers);

return Redirect::back();
}

public function deleteOrganizer(string $integrationId, string $organizerId): RedirectResponse
{
$this->organizerRepository->delete(new Organizer(
Uuid::uuid4(),
Uuid::fromString($integrationId),
Uuid::fromString($organizerId)
$organizerId
));

return Redirect::back();
Expand All @@ -313,7 +329,7 @@ public function requestActivation(string $id, RequestActivationRequest $request)
$organization = OrganizationMapper::mapActivationRequest($request);
$this->organizationRepository->save($organization);

$organizers = OrganizerMapper::map($request, $id);
$organizers = OrganizerMapper::mapActivationRequest($request, $id);
$this->organizerRepository->create(...$organizers);

$this->integrationRepository->requestActivation(Uuid::fromString($id), $organization->id, $request->input('coupon'));
Expand Down Expand Up @@ -388,7 +404,7 @@ private function guardUserIsContact(Request $request, string $integrationId): ?R

public function getIntegrationOrganizersWithTestOrganizer(Integration $integration): Collection
{
$organizerIds = collect($integration->organizers())->map(fn (Organizer $organizer) => $organizer->organizerId->toString());
$organizerIds = collect($integration->organizers())->map(fn (Organizer $organizer) => $organizer->organizerId);
$uitpasOrganizers = $this->searchClient->findUiTPASOrganizers(...$organizerIds)->getMember()?->getItems();

$organizers = collect($uitpasOrganizers)->map(function (SapiOrganizer $organizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public function rules(): array
{
$rules = collect([
...(new CreateOrganizationRequest())->rules(),
...(new UpdateIntegrationOrganizersRequest())->rules(),
'coupon' => ['nullable', 'string', 'max:255'],
'organizers' => ['required','array'],
'organizers.*.name' => ['required', 'string'],
'organizers.*.id' => ['required', 'string'],
]);

if (!$this->isAccountingInfoRequired() || $this->isUITPAS()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\FormRequests;

use Illuminate\Foundation\Http\FormRequest;

final class UpdateIntegrationOrganizersRequest extends FormRequest
{
public function rules(): array
{
return [
'organizers' => ['required', 'array'],
'organizers.*.name' => ['required', 'string'],
'organizers.*.id' => ['required', 'string'],
];
}
}
16 changes: 14 additions & 2 deletions app/Domain/Integrations/Mappers/OrganizerMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace App\Domain\Integrations\Mappers;

use App\Domain\Integrations\FormRequests\RequestActivationRequest;
use App\Domain\Integrations\FormRequests\UpdateIntegrationOrganizersRequest;
use App\Domain\Integrations\Organizer;
use Illuminate\Http\Request;
use Ramsey\Uuid\Uuid;

final class OrganizerMapper
{
/**
* @return Organizer[]
*/
public static function map(RequestActivationRequest $request, string $id): array
public static function map(Request $request, string $id): array
{
/**
* @var Organizer[] $organizers
Expand All @@ -24,10 +26,20 @@ public static function map(RequestActivationRequest $request, string $id): array
$organizers[] = new Organizer(
Uuid::uuid4(),
Uuid::fromString($id),
Uuid::fromString($organizer['id'])
$organizer['id']
);
}

return $organizers;
}

public static function mapUpdateOrganizers(UpdateIntegrationOrganizersRequest $request, string $id): array
{
return self::map($request, $id);
}

public static function mapActivationRequest(RequestActivationRequest $request, string $id): array
{
return self::map($request, $id);
}
}
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Models/OrganizerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function toDomain(): Organizer
return new Organizer(
Uuid::fromString($this->id),
Uuid::fromString($this->integration_id),
Uuid::fromString($this->organizer_id),
$this->organizer_id,
);
}
}
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Organizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public function __construct(
public UuidInterface $id,
public UuidInterface $integrationId,
public UuidInterface $organizerId
public string $organizerId
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function create(Organizer ...$organizers): void
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
'organizer_id' => $organizer->organizerId,
]);
}
});
Expand All @@ -26,7 +26,7 @@ public function create(Organizer ...$organizers): void
public function delete(Organizer $organizer): void
{
OrganizerModel::query()
->where('organizer_id', $organizer->organizerId->toString())
->where('organizer_id', $organizer->organizerId)
->where('integration_id', $organizer->integrationId->toString())
->delete();
}
Expand Down
3 changes: 1 addition & 2 deletions app/Nova/Actions/ActivateUitpasIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ public function handle(ActionFields $fields, Collection $integrations): ActionRe
$organizerArray = array_map('trim', explode(',', $organizers));

foreach ($organizerArray as $organizer) {
$organizerId = Uuid::fromString($organizer);
$this->organizerRepository->create(
new Organizer(
Uuid::uuid4(),
Uuid::fromString($integration->id),
$organizerId
$organizer
)
);
}
Expand Down
3 changes: 1 addition & 2 deletions app/Nova/Actions/AddOrganizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public function handle(ActionFields $fields, Collection $integrations): ActionRe

/** @var string $organizationIdAsString */
$organizationIdAsString = $fields->get('organizer_id');
$organizationId = Uuid::fromString($organizationIdAsString);

$this->organizerRepository->create(
new Organizer(
Uuid::uuid4(),
Uuid::fromString($integration->id),
$organizationId
$organizationIdAsString
)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('organizers', function (Blueprint $table) {
$table->char('organizer_id', 36)->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('organizers', function (Blueprint $table) {
$table->uuid('organizer_id')->change();
});
}
};
3 changes: 3 additions & 0 deletions resources/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
"title": "Organizers",
"description": "Below you see an overview of the UiTdatabank organizers for which you can execute actions in the UiTPAS API.",
"add": "Add organizer",
"update_dialog": {
"question": "Select the UiTdatabank organizers for which you can execute actions in UiTPAS."
},
"delete_dialog": {
"title": "Remove organizer",
"question": "Are you sure you want to remove {{name}} from your integration?"
Expand Down
3 changes: 3 additions & 0 deletions resources/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
"title": "Organisaties",
"description": "Hieronder vind je een overzicht van de UiTdatabank organisaties waarvoor je acties kan uitvoeren in de UiTPAS API.",
"add": "Organisatie toevoegen",
"update_dialog": {
"question": "Geef de UiTdatabank-organisaties op waarvoor je acties in UiTPAS wilt uitvoeren."
},
"delete_dialog": {
"title": "Organisatie verwijderen",
"question": "Ben je zeker dat je {{name}} wilt verwijderen van je integratie?"
Expand Down
Loading

0 comments on commit 07b888b

Please sign in to comment.