Skip to content

Commit

Permalink
Merge pull request #1214 from cultuurnet/PPF-460-uitpas-activation
Browse files Browse the repository at this point in the history
PPF-460-UiTPAS activation
  • Loading branch information
vhande authored Jun 28, 2024
2 parents bb2fd05 + a35457e commit 17a49d0
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 27 deletions.
7 changes: 7 additions & 0 deletions app/Domain/Integrations/Controllers/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use App\Domain\Integrations\IntegrationUrl;
use App\Domain\Integrations\KeyVisibility;
use App\Domain\Integrations\Mappers\OrganizationMapper;
use App\Domain\Integrations\Mappers\OrganizerMapper;
use App\Domain\Integrations\Mappers\StoreContactMapper;
use App\Domain\Integrations\Mappers\StoreIntegrationMapper;
use App\Domain\Integrations\Mappers\StoreIntegrationUrlMapper;
Expand All @@ -33,6 +34,7 @@
use App\Domain\Integrations\Mappers\UpdateIntegrationUrlsMapper;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\IntegrationUrlRepository;
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Domain\KeyVisibilityUpgrades\KeyVisibilityUpgrade;
use App\Domain\Organizations\Repositories\OrganizationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
Expand Down Expand Up @@ -63,6 +65,7 @@ public function __construct(
private readonly ContactRepository $contactRepository,
private readonly ContactKeyVisibilityRepository $contactKeyVisibilityRepository,
private readonly OrganizationRepository $organizationRepository,
private readonly OrganizerRepository $organizerRepository,
private readonly CouponRepository $couponRepository,
private readonly Auth0ClientRepository $auth0ClientRepository,
private readonly UiTiDv1ConsumerRepository $uitidV1ConsumerRepository,
Expand Down Expand Up @@ -172,6 +175,7 @@ public function show(string $id): Response
'oldCredentialsExpirationDate' => $oldCredentialsExpirationDate,
'email' => Auth::user()?->email,
'subscriptions' => $this->subscriptionRepository->all(),
'organizers' => session('organizers'),
]);
}

Expand Down Expand Up @@ -288,6 +292,9 @@ public function requestActivation(string $id, RequestActivationRequest $request)
$organization = OrganizationMapper::mapActivationRequest($request);
$this->organizationRepository->save($organization);

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

$this->integrationRepository->requestActivation(Uuid::fromString($id), $organization->id, $request->input('coupon'));

return Redirect::back();
Expand Down
42 changes: 42 additions & 0 deletions app/Domain/Integrations/Controllers/OrganizerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Controllers;

use App\Domain\Integrations\FormRequests\GetOrganizersRequest;
use App\Http\Controllers\Controller;
use App\Search\Sapi3\SearchService;
use CultuurNet\SearchV3\ValueObjects\Organizer;
use Illuminate\Http\JsonResponse;

final class OrganizerController extends Controller
{
public function __construct(private readonly SearchService $searchService)
{
}

public function index(GetOrganizersRequest $request): JsonResponse
{
try {
$organizerName = $request->input('name');

$data = $this->searchService->searchUiTPASOrganizer($organizerName)->getMember()?->getItems() ?? [];

return new JsonResponse(
array_map(function (Organizer $organizer) {
return [
'id' => $organizer->getCdbid(),
'name' => $organizer->getName()?->getValues(),
];
}, $data)
);

} catch (\Exception $e) {
return new JsonResponse(
['exception' => $e->getMessage()]
);
;
}
}
}
20 changes: 20 additions & 0 deletions app/Domain/Integrations/FormRequests/GetOrganizersRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\FormRequests;

use Illuminate\Foundation\Http\FormRequest;

final class GetOrganizersRequest extends FormRequest
{
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => ['required', 'string'],
];
}
}
26 changes: 23 additions & 3 deletions app/Domain/Integrations/FormRequests/RequestActivationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Domain\Integrations\FormRequests;

use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationType;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
Expand All @@ -24,25 +25,44 @@ public function rules(): array
$rules = collect([
...(new CreateOrganizationRequest())->rules(),
'coupon' => ['nullable', 'string', 'max:255'],
'organizers' => ['required','array'],
'organizers.*.name' => ['required', 'string'],
'organizers.*.id' => ['required', 'string'],
]);

if (!$this->isAccountingInfoRequired()) {
if (!$this->isAccountingInfoRequired() || $this->isUITPAS()) {
$rules->forget(['organization.invoiceEmail', 'organization.vat', 'coupon']);
}

if (!$this->isUITPAS()) {
$rules->forget(['organizers']);
}

return $rules->toArray();
}

private function isAccountingInfoRequired(): bool
private function fetchIntegration(): Integration
{
/** @var IntegrationRepository $integrationRepository */
$integrationRepository = App::get(IntegrationRepository::class);
$integration = $integrationRepository->getById(Uuid::fromString($this->id));
return $integrationRepository->getById(Uuid::fromString($this->id));
}


private function isAccountingInfoRequired(): bool
{
$integration = $this->fetchIntegration();

/** @var SubscriptionRepository $subscriptionRepository */
$subscriptionRepository = App::get(SubscriptionRepository::class);
$subscription = $subscriptionRepository->getById($integration->subscriptionId);

return $integration->type !== IntegrationType::EntryApi || $subscription->price > 0.0;
}

private function isUITPAS(): bool
{
$integration = $this->fetchIntegration();
return $integration->type === IntegrationType::UiTPAS;
}
}
33 changes: 33 additions & 0 deletions app/Domain/Integrations/Mappers/OrganizerMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Mappers;

use App\Domain\Integrations\FormRequests\RequestActivationRequest;
use App\Domain\Integrations\Organizer;
use Ramsey\Uuid\Uuid;

final class OrganizerMapper
{
/**
* @return Organizer[]
*/
public static function map(RequestActivationRequest $request, string $id): array
{
/**
* @var Organizer[] $organizers
*/
$organizers = [];

foreach ($request->input('organizers') ?? [] as $organizer) {
$organizers[] = new Organizer(
Uuid::uuid4(),
Uuid::fromString($id),
Uuid::fromString($organizer['id'])
);
}

return $organizers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

use App\Domain\Integrations\Models\OrganizerModel;
use App\Domain\Integrations\Organizer;
use Illuminate\Support\Facades\DB;

final class EloquentOrganizerRepository implements OrganizerRepository
{
public function create(Organizer $organizer): void
public function create(Organizer ...$organizers): void
{
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
]);
DB::transaction(function () use ($organizers): void {
foreach ($organizers as $organizer) {
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
]);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface OrganizerRepository
{
public function create(Organizer $organizer): void;
public function create(Organizer ...$organizer): void;
}
1 change: 1 addition & 0 deletions app/Search/Sapi3/Sapi3SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function searchUiTPASOrganizer(string $name): PagedCollection
$searchQuery = new SearchQuery();
$searchQuery->addParameter(new Label('UiTPAS'));
$searchQuery->addParameter(new Name($name));
$searchQuery->setLimit(5);
$searchQuery->setEmbed(true);

return $this->searchClient->searchOrganizers($searchQuery);
Expand Down
1 change: 1 addition & 0 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
'organization.address.zip' => 'postcode',
'organization.address.city' => 'city',
'organization.vat' => 'VAT or company number',
'organizers' => 'organizers'
],

];
1 change: 1 addition & 0 deletions lang/nl/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
'organization.address.zip' => 'postcode',
'organization.address.city' => 'gemeente',
'organization.vat' => 'BTW of ondernemingsnummer',
'organizers' => 'organisaties'
],

];
Expand Down
8 changes: 8 additions & 0 deletions resources/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@
"coupon": "Coupon",
"plan": "Subscription",
"year": "year"
},
"uitpas": {
"partner": "Partner",
"organizers": {
"title": "UiTdatabank organizers",
"info": "Enter the UiTdatabank organizers for which you want to execute actions in UiTPAS.",
"label": "Organizers"
}
}
},
"documentation": {
Expand Down
8 changes: 8 additions & 0 deletions resources/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@
"coupon": "Coupon",
"plan": "Abonnement",
"year": "jaar"
},
"uitpas": {
"partner": "Partner",
"organizers": {
"title": "UiTdatabank organisaties",
"info": "Geef de UiTdatabank organisaties op waarvoor je acties in UiTPAS wilt uitvoeren.",
"label": "Organisaties"
}
}
},
"documentation": {
Expand Down
Loading

0 comments on commit 17a49d0

Please sign in to comment.