Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

III-4866 refactor EditPlaceRestController to 2 handlers-1/2-updateAddress() #1101

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
11 changes: 9 additions & 2 deletions app/Place/PlaceControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use CultuurNet\UDB3\Http\Import\RemoveEmptyArraysRequestBodyParser;
use CultuurNet\UDB3\Http\Place\ImportPlaceRequestHandler;
use CultuurNet\UDB3\Http\Place\LegacyPlaceRequestBodyParser;
use CultuurNet\UDB3\Http\Place\UpdateAddressRequestHandler;
use CultuurNet\UDB3\Http\Place\UpdateMajorInfoRequestHandler;
use CultuurNet\UDB3\Http\Place\EditPlaceRestController;
use CultuurNet\UDB3\Http\Request\Body\CombinedRequestBodyParser;
Expand All @@ -31,7 +32,7 @@ public function connect(Application $app): ControllerCollection
$controllers->post('/', ImportPlaceRequestHandler::class);
$controllers->put('/{placeId}', ImportPlaceRequestHandler::class);

$controllers->put('/{cdbid}/address/{lang}/', 'place_editing_controller:updateAddress');
$controllers->put('/{placeId}/address/{language}/', UpdateAddressRequestHandler::class);
$controllers->put('/{cdbid}/booking-info/', 'place_editing_controller:updateBookingInfo');
$controllers->put('/{cdbid}/contact-point/', 'place_editing_controller:updateContactPoint');
$controllers->put('/{placeId}/major-info/', UpdateMajorInfoRequestHandler::class);
Expand All @@ -51,7 +52,7 @@ public function connect(Application $app): ControllerCollection
$controllers->get('/{cdbid}/events/', 'place_editing_controller:getEvents');
$controllers->post('/{itemId}/images/main/', 'place_editing_controller:selectMainImage');
$controllers->post('/{itemId}/images/{mediaObjectId}/', 'place_editing_controller:updateImage');
$controllers->post('/{cdbid}/address/{lang}/', 'place_editing_controller:updateAddress');
$controllers->post('/{placeId}/address/{language}/', UpdateAddressRequestHandler::class);
$controllers->post('/{cdbid}/typical-age-range/', 'place_editing_controller:updateTypicalAgeRange');
$controllers->post('/{placeId}/major-info/', UpdateMajorInfoRequestHandler::class);
$controllers->post('/{cdbid}/booking-info/', 'place_editing_controller:updateBookingInfo');
Expand All @@ -73,6 +74,12 @@ function (Application $app) {
}
);

$app[UpdateAddressRequestHandler::class] = $app->share(
fn (Application $app) => new UpdateAddressRequestHandler(
$app['event_command_bus']
)
);

$app[ImportPlaceRequestHandler::class] = $app->share(
fn (Application $application) => new ImportPlaceRequestHandler(
$app['place_repository'],
Expand Down
4 changes: 2 additions & 2 deletions app/Place/PlaceEditingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace CultuurNet\UDB3\Silex\Place;

use Broadway\UuidGenerator\Rfc4122\Version4Generator;
use CultuurNet\UDB3\Offer\DefaultOfferEditingService;
use CultuurNet\UDB3\Place\Commands\PlaceCommandFactory;
use CultuurNet\UDB3\Place\DefaultPlaceEditingService;
use CultuurNet\UDB3\Place\PlaceOrganizerRelationService;
use CultuurNet\UDB3\Place\ReadModel\Relations\PlaceRelationsRepository;
use Silex\Application;
Expand All @@ -21,7 +21,7 @@ public function register(Application $app)
{
$app['place_editing_service'] = $app->share(
function ($app) {
return new DefaultPlaceEditingService(
return new DefaultOfferEditingService(
$app['event_command_bus'],
new Version4Generator(),
$app['place_jsonld_repository'],
Expand Down
37 changes: 0 additions & 37 deletions src/Http/Place/EditPlaceRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
namespace CultuurNet\UDB3\Http\Place;

use CultuurNet\UDB3\Event\ReadModel\Relations\EventRelationsRepository;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Media\MediaManagerInterface;
use CultuurNet\UDB3\Place\PlaceEditingServiceInterface;
use CultuurNet\UDB3\Http\Deserializer\Address\AddressJSONDeserializer;
use CultuurNet\UDB3\HttpFoundation\Response\NoContent;
use CultuurNet\UDB3\Http\OfferRestBaseController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use CultuurNet\UDB3\StringLiteral;

class EditPlaceRestController extends OfferRestBaseController
{
Expand All @@ -26,11 +19,6 @@ class EditPlaceRestController extends OfferRestBaseController
*/
private $eventRelationsRepository;

/**
* @var AddressJSONDeserializer
*/
private $addressDeserializer;

/**
* Constructs a RestController.
*
Expand All @@ -42,31 +30,6 @@ public function __construct(
) {
parent::__construct($placeEditor, $mediaManager);
$this->eventRelationsRepository = $eventRelationsRepository;


$this->addressDeserializer = new AddressJSONDeserializer();
}

public function placeContext(): BinaryFileResponse
{
$response = new BinaryFileResponse('/udb3/api/1.0/place.jsonld');
$response->headers->set('Content-Type', 'application/ld+json');
return $response;
}

public function updateAddress(Request $request, string $cdbid, string $lang): Response
{
$address = $this->addressDeserializer->deserialize(
new StringLiteral($request->getContent())
);

$this->editor->updateAddress(
$cdbid,
$address,
new Language($lang)
);

return new NoContent();
}

public function getEvents(string $cdbid): JsonResponse
Expand Down
43 changes: 43 additions & 0 deletions src/Http/Place/UpdateAddressRequestHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Http\Place;

use Broadway\CommandHandling\CommandBus;
use CultuurNet\UDB3\Http\Deserializer\Address\AddressJSONDeserializer;
use CultuurNet\UDB3\Http\Request\RouteParameters;
use CultuurNet\UDB3\Http\Response\NoContentResponse;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Place\Commands\UpdateAddress;
use CultuurNet\UDB3\StringLiteral;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

final class UpdateAddressRequestHandler implements RequestHandlerInterface
{
private CommandBus $commandBus;

public function __construct(CommandBus $commandBus)
{
$this->commandBus = $commandBus;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$routeParameters = new RouteParameters($request);
$placeId = $routeParameters->getPlaceId();
$language = $routeParameters->getLanguage();

$address = (new AddressJSONDeserializer())->deserialize(
new StringLiteral($request->getBody()->getContents())
);

$this->commandBus->dispatch(
new UpdateAddress($placeId, $address, Language::fromUdb3ModelLanguage($language))
);

return new NoContentResponse();
}
}
22 changes: 0 additions & 22 deletions src/Place/DefaultPlaceEditingService.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Place/PlaceEditingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace CultuurNet\UDB3\Place;

use CultuurNet\UDB3\Address\Address;
use CultuurNet\UDB3\ContactPoint;
use CultuurNet\UDB3\Description;
use CultuurNet\UDB3\Language;
Expand All @@ -14,7 +13,6 @@

interface PlaceEditingServiceInterface
{
public function updateAddress(string $id, Address $address, Language $language): void;
public function updateDescription(string $id, Language $language, Description $description): void;
public function updateTypicalAgeRange(string $id, AgeRange $ageRange): void;
public function deleteTypicalAgeRange(string $id): void;
Expand Down
8 changes: 3 additions & 5 deletions src/Place/PlaceOrganizerRelationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace CultuurNet\UDB3\Place;

use CultuurNet\UDB3\Offer\OfferEditingServiceInterface;
use CultuurNet\UDB3\Organizer\OrganizerRelationServiceInterface;
use CultuurNet\UDB3\Place\ReadModel\Relations\PlaceRelationsRepository;

class PlaceOrganizerRelationService implements OrganizerRelationServiceInterface
{
/**
* @var PlaceEditingServiceInterface
*/
private $editingService;
private OfferEditingServiceInterface $editingService;

/**
* @var PlaceRelationsRepository
Expand All @@ -21,7 +19,7 @@ class PlaceOrganizerRelationService implements OrganizerRelationServiceInterface


public function __construct(
PlaceEditingServiceInterface $editingService,
OfferEditingServiceInterface $editingService,
PlaceRelationsRepository $relationsRepository
) {
$this->editingService = $editingService;
Expand Down
142 changes: 0 additions & 142 deletions tests/Http/Place/EditPlaceRestControllerTest.php

This file was deleted.

Loading