Skip to content

Commit

Permalink
Merge pull request #362 from cultuurnet/PPF-230-map-platform-id
Browse files Browse the repository at this point in the history
PPF-230 add projectRepository to OpenProject
  • Loading branch information
LucWollants authored Nov 24, 2023
2 parents 2588480 + 3d67e21 commit f2d510a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 42 deletions.
6 changes: 2 additions & 4 deletions app/Project/ProjectControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ public function connect(Application $app)
};

$app['import_project_controller'] = function (Application $app) {
return new ImportProjectController(
$app['command_bus'],
$app['project_repository']
);
return new ImportProjectController($app['command_bus']);
};

$app['open_project_controller'] = function (Application $app) {
return new OpenProjectController(
$app['uitid_user_session_service'],
$app['session'],
$app['project_repository'],
$app['config']['platform_host'],
$app['config']['widget_host']
);
Expand Down
2 changes: 1 addition & 1 deletion app/WebApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function registerProviders()
new Path('^/event/', 'GET'),
new Path('^/upload', 'POST'),
new Path('^/project/.*$', 'POST'),
new Path('^/project/[0-9]*/widget/.*$', 'GET'),
new Path('^/project/[A-z0-9\-]*/widget/.*$', 'GET'),
new Path('^.*$', 'OPTIONS'),
]
),
Expand Down
15 changes: 2 additions & 13 deletions src/Project/Controller/ImportProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace CultuurNet\ProjectAanvraag\Project\Controller;

use CultuurNet\ProjectAanvraag\Entity\Project;
use CultuurNet\ProjectAanvraag\Project\Command\ImportProject;
use Doctrine\ORM\EntityRepository;
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -18,15 +16,9 @@ class ImportProjectController
*/
private $commandBus;

/**
* @var EntityRepository
*/
protected $projectRepository;

public function __construct(MessageBusSupportingMiddleware $commandBus, EntityRepository $projectRepository)
public function __construct(MessageBusSupportingMiddleware $commandBus)
{
$this->commandBus = $commandBus;
$this->projectRepository = $projectRepository;
}

public function importProject(string $uuid, Request $request): JsonResponse
Expand All @@ -50,9 +42,6 @@ public function importProject(string $uuid, Request $request): JsonResponse
)
);

/** @var Project $project */
$project = $this->projectRepository->findOneBy(['platformUuid' => $uuid]);

return new JsonResponse(['databaseId' => $project->getId()]);
return new JsonResponse();
}
}
25 changes: 21 additions & 4 deletions src/Project/Controller/OpenProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use CultuurNet\Auth\TokenCredentials;
use CultuurNet\Auth\User;
use CultuurNet\ProjectAanvraag\Entity\Project;
use CultuurNet\UiTIDProvider\User\UserSessionService;
use Doctrine\ORM\EntityRepository;
use Guzzle\Http\Client;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -23,20 +25,32 @@ final class OpenProjectController
* @var Session
*/
private $session;

/**
* @var EntityRepository
*/
protected $projectRepository;

/**
* @var string
*/
private $platformUrl;

/*
/**
* @var string
*/
private $widgetUrl;

public function __construct(UserSessionService $userSessionService, Session $session, string $platformUrl, string $widgetUrl)
{
public function __construct(
UserSessionService $userSessionService,
Session $session,
EntityRepository $projectRepository,
string $platformUrl,
string $widgetUrl
) {
$this->userSessionService = $userSessionService;
$this->session = $session;
$this->projectRepository = $projectRepository;
$this->platformUrl = $platformUrl;
$this->widgetUrl = $widgetUrl;
}
Expand All @@ -60,7 +74,10 @@ public function openProject(Request $request, string $id): RedirectResponse
)
);

/** @var Project $project */
$project = $this->projectRepository->findOneBy(['platformUuid' => $id]);

$this->session->set('id_token', $tokenString);
return new RedirectResponse($this->widgetUrl . '/project/' . $id);
return new RedirectResponse($this->widgetUrl . '/project/' . $project->getId());
}
}
22 changes: 2 additions & 20 deletions test/Project/Controller/ImportProjectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace CultuurNet\ProjectAanvraag\Project\Controller;

use CultuurNet\ProjectAanvraag\Entity\Project;
use CultuurNet\ProjectAanvraag\Project\Command\ImportProject;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;
Expand All @@ -23,11 +21,6 @@ class ImportProjectControllerTest extends TestCase
*/
private $messageBus;

/**
* @var EntityRepository & MockObject
*/
private $projectRepository;

/**
* @var Request & MockObject
*/
Expand All @@ -39,12 +32,7 @@ public function setUp()

$this->request = $this->createMock(Request::class);

$this->projectRepository = $this->createMock(EntityRepository::class);

$this->controller = new ImportProjectController(
$this->messageBus,
$this->projectRepository
);
$this->controller = new ImportProjectController($this->messageBus);
}

public function testImportProject()
Expand Down Expand Up @@ -79,13 +67,7 @@ public function testImportProject()
->method('handle')
->with($importProject);

$this->projectRepository
->expects($this->once())
->method('findOneBy')
->with(['platformUuid' => $platformUuid])
->willReturn((new Project())->setId(123));

$response = $this->controller->importProject($platformUuid, $this->request);
$this->assertEquals(new JsonResponse(['databaseId' => 123]), $response, 'It correctly handles the request');
$this->assertEquals(new JsonResponse(), $response, 'It correctly handles the request');
}
}

0 comments on commit f2d510a

Please sign in to comment.