-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from cultuurnet/PPF-230-endpoint-for-ppf
PPF-230 endpoint for ppf
- Loading branch information
Showing
12 changed files
with
397 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace CultuurNet\ProjectAanvraag\Project\Command; | ||
|
||
class ImportProject | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $userId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $groupId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $platformUuid; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $testApiKeySapi3; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $liveApiKeySapi3; | ||
|
||
public function __construct( | ||
string $platformUuid, | ||
string $userId, | ||
string $name, | ||
string $description, | ||
int $groupId, | ||
string $testApiKeySapi3, | ||
string $liveApiKeySapi3 | ||
) { | ||
$this->platformUuid = $platformUuid; | ||
$this->userId = $userId; | ||
$this->name = $name; | ||
$this->description = $description; | ||
$this->groupId = $groupId; | ||
$this->testApiKeySapi3 = $testApiKeySapi3; | ||
$this->liveApiKeySapi3 = $liveApiKeySapi3; | ||
} | ||
|
||
public function getUserId(): string | ||
{ | ||
return $this->userId; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return $this->description; | ||
} | ||
|
||
public function getGroupId(): int | ||
{ | ||
return $this->groupId; | ||
} | ||
|
||
public function getPlatformUuid(): string | ||
{ | ||
return $this->platformUuid; | ||
} | ||
|
||
public function getTestApiKeySapi3(): string | ||
{ | ||
return $this->testApiKeySapi3; | ||
} | ||
|
||
public function getLiveApiKeySapi3(): string | ||
{ | ||
return $this->liveApiKeySapi3; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Project/CommandHandler/ImportProjectCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace CultuurNet\ProjectAanvraag\Project\CommandHandler; | ||
|
||
use CultuurNet\ProjectAanvraag\Entity\Project; | ||
use CultuurNet\ProjectAanvraag\Entity\User; | ||
use CultuurNet\ProjectAanvraag\Project\Command\ImportProject; | ||
use CultuurNet\ProjectAanvraag\User\UserInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class ImportProjectCommandHandler | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
public function __construct( | ||
EntityManagerInterface $entityManager, | ||
LoggerInterface $logger | ||
) { | ||
$this->entityManager = $entityManager; | ||
$this->logger = $logger; | ||
} | ||
|
||
public function handle(ImportProject $importProject): void | ||
{ | ||
$this->logger->debug('Start handling ImportProject for ' . $importProject->getName()); | ||
|
||
$project = new Project(); | ||
$project->setName($importProject->getName()); | ||
$project->setDescription($importProject->getDescription()); | ||
$project->setGroupId($importProject->getGroupId()); | ||
$project->setUserId($importProject->getUserId()); | ||
$project->setPlatformUuid($importProject->getPlatformUuid()); | ||
$project->setTestApiKeySapi3($importProject->getTestApiKeySapi3()); | ||
$project->setLiveApiKeySapi3($importProject->getLiveApiKeySapi3()); | ||
$project->setStatus(Project::PROJECT_STATUS_APPLICATION_SENT); | ||
|
||
$this->entityManager->persist($project); | ||
|
||
$this->entityManager->flush(); | ||
|
||
$this->logger->debug('Finished handling ImportProject for ' . $importProject->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace CultuurNet\ProjectAanvraag\Project\Controller; | ||
|
||
use CultuurNet\ProjectAanvraag\Project\Command\ImportProject; | ||
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ImportProjectController | ||
{ | ||
use ValidateRequiredFieldsTrait; | ||
|
||
/** | ||
* @var MessageBusSupportingMiddleware | ||
*/ | ||
private $commandBus; | ||
|
||
public function __construct(MessageBusSupportingMiddleware $commandBus) | ||
{ | ||
$this->commandBus = $commandBus; | ||
} | ||
|
||
public function importProject(string $uuid, Request $request): JsonResponse | ||
{ | ||
$postedProject = json_decode($request->getContent()); | ||
|
||
$this->validate( | ||
['userId', 'name', 'summary', 'groupId', 'testApiKeySapi3', 'liveApiKeySapi3'], | ||
$postedProject | ||
); | ||
|
||
$this->commandBus->handle( | ||
new ImportProject( | ||
$uuid, | ||
$postedProject->userId, | ||
$postedProject->name, | ||
$postedProject->summary, | ||
$postedProject->groupId, | ||
$postedProject->testApiKeySapi3, | ||
$postedProject->liveApiKeySapi3 | ||
) | ||
); | ||
|
||
return new JsonResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace CultuurNet\ProjectAanvraag\Project\Controller; | ||
|
||
use CultuurNet\ProjectAanvraag\Core\Exception\MissingRequiredFieldsException; | ||
|
||
trait ValidateRequiredFieldsTrait | ||
{ | ||
/** | ||
* Validate if all required fields are in the data. | ||
* @param \stdClass $data | ||
* @throws MissingRequiredFieldsException | ||
*/ | ||
private function validate($requiredFields, \stdClass $data = null) | ||
{ | ||
$emptyFields = []; | ||
foreach ($requiredFields as $field) { | ||
if (empty($data->$field)) { | ||
$emptyFields[] = $field; | ||
} | ||
} | ||
|
||
if (!empty($emptyFields)) { | ||
throw new MissingRequiredFieldsException('Some required fields are missing: ' . implode(', ', $emptyFields)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.