Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

feat: Add backend api support for Local Authority UI #191

Merged
merged 1 commit into from
Jul 1, 2024
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"league/flysystem-webdav": "1.0.10",
"monolog/monolog": "^2.9",
"olcs/olcs-logging": "^7.0",
"olcs/olcs-transfer": "^7.1.2",
"olcs/olcs-transfer": "^7.4.0",
"olcs/olcs-utils": "^6.0.0",
"olcs/olcs-xmltools": "~7.0.0",
"oro/doctrine-extensions": "^2",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions module/Api/config/command-map.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1300,4 +1300,7 @@
Command\Messaging\Conversation\StoreEnhancedSnapshot::class => CommandHandler\Messaging\Conversation\StoreEnhancedSnapshot::class,
TransferCommand\Messaging\Message\Create::class => CommandHandler\Messaging\Message\Create::class,
TransferCommand\Messaging\Conversation\Create::class => CommandHandler\Messaging\Conversation\Create::class,

// Local Authority
TransferCommand\LocalAuthority\Update::class => CommandHandler\LocalAuthority\Update::class,
];
1 change: 1 addition & 0 deletions module/Api/config/query-map.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@

TransferQuery\RefData\RefDataList::class => QueryHandler\RefData\RefDataList::class,
TransferQuery\LocalAuthority\LocalAuthorityList::class => QueryHandler\LocalAuthority\LocalAuthorityList::class,
TransferQuery\LocalAuthority\ById::class => QueryHandler\LocalAuthority\ById::class,

// SystemParameter
TransferQuery\SystemParameter\SystemParameter::class => QueryHandler\SystemParameter\SystemParameter::class,
Expand Down
5 changes: 5 additions & 0 deletions module/Api/config/validation-map/local-authority.config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

use Dvsa\Olcs\Api\Domain\QueryHandler;
use Dvsa\Olcs\Api\Domain\CommandHandler;
use Dvsa\Olcs\Api\Domain\Validation\Handlers\Misc\IsInternalUser;
use Dvsa\Olcs\Api\Domain\Validation\Handlers\Misc\IsSystemAdmin;

return [
// Queries
QueryHandler\LocalAuthority\LocalAuthorityList::class => IsInternalUser::class,
QueryHandler\LocalAuthority\ById::class => IsSystemAdmin::class,
// Commands
CommandHandler\LocalAuthority\Update::class => IsSystemAdmin::class
];
39 changes: 39 additions & 0 deletions module/Api/src/Domain/CommandHandler/LocalAuthority/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Dvsa\Olcs\Api\Domain\CommandHandler\LocalAuthority;

use Dvsa\Olcs\Api\Domain\Command\Result;
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCommandHandler;
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo;
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity;
use Dvsa\Olcs\Transfer\Command\CommandInterface;
use Dvsa\Olcs\Transfer\Command\LocalAuthority\Update as UpdateLocalAuthorityCmd;

/**
* Update a Local Authority
*/
final class Update extends AbstractCommandHandler
jerotire marked this conversation as resolved.
Show resolved Hide resolved
{
protected $repoServiceName = 'LocalAuthority';

public function handleCommand(CommandInterface $command): Result
{
/**
* @var UpdateLocalAuthorityCmd $command
* @var LocalAuthorityEntity $localAuthority
* @var LocalAuthorityRepo $repo
*/
$repo = $this->getRepo();
$localAuthority = $repo->fetchUsingId($command);
$localAuthority->update(
$command->getDescription(),
$command->getEmailAddress()
);

$repo->save($localAuthority);

$this->result->addId('LocalAuthority', $localAuthority->getId());
$this->result->addMessage("Local Authority '{$localAuthority->getId()}' updated");
return $this->result;
}
}
13 changes: 13 additions & 0 deletions module/Api/src/Domain/QueryHandler/LocalAuthority/ById.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Dvsa\Olcs\Api\Domain\QueryHandler\LocalAuthority;

use Dvsa\Olcs\Api\Domain\QueryHandler\AbstractQueryByIdHandler;

/**
* Retrieve a local authority by id
*/
final class ById extends AbstractQueryByIdHandler
jerotire marked this conversation as resolved.
Show resolved Hide resolved
{
protected $repoServiceName = 'LocalAuthority';
}
6 changes: 6 additions & 0 deletions module/Api/src/Entity/Bus/LocalAuthority.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
*/
class LocalAuthority extends AbstractLocalAuthority
{
public function update(string $description, ?string $emailAddress): LocalAuthority
{
$this->description = $description;
$this->emailAddress = $emailAddress;
return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\LocalAuthority;

use Dvsa\Olcs\Api\Domain\CommandHandler\LocalAuthority\Update as UpdateHandler;
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo;
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity;
use Dvsa\Olcs\Transfer\Command\LocalAuthority\Update as UpdateCmd;
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase;
use Mockery as m;

/**
* Update Local Authority Test
*/
class UpdateTest extends AbstractCommandHandlerTestCase
{
public function setUp(): void
{
$this->sut = new UpdateHandler();
$this->mockRepo('LocalAuthority', LocalAuthorityRepo::class);
parent::setUp();
}

public function testHandleCommand()
{
$id = 999;
$description = 'lta descr';
$emailAddress = '[email protected]';

$cmdData = [
'id' => $id,
'description' => $description,
'emailAddress' => $emailAddress,
];

$command = UpdateCmd::create($cmdData);

$entity = m::mock(LocalAuthorityEntity::class);
$entity->shouldReceive('update')
->once()
->with($description, $emailAddress);
$entity->shouldReceive('getId')
->twice()
->andReturn($id);

$this->repoMap['LocalAuthority']
->shouldReceive('fetchUsingId')
->once()
->with($command)
->andReturn($entity);

$this->repoMap['LocalAuthority']
->shouldReceive('save')
->once()
->with(m::type(LocalAuthorityEntity::class));

$result = $this->sut->handleCommand($command);

$expected = [
'id' => ['LocalAuthority' => $id],
'messages' => ["Local Authority '" . $id . "' updated"]
];

$this->assertEquals($expected, $result->toArray());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Dvsa\OlcsTest\Api\Domain\QueryHandler\LocalAuthority;

use Dvsa\Olcs\Api\Domain\QueryHandler\LocalAuthority\ById as ToggleByIdHandler;
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo;
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity;
use Dvsa\Olcs\Transfer\Query\LocalAuthority\ById as QryClass;
use Dvsa\OlcsTest\Api\Domain\QueryHandler\AbstractQueryByIdHandlerTest;

/**
* Local Authority ById Test
*/
class ByIdTest extends AbstractQueryByIdHandlerTest
{
protected $sutClass = ToggleByIdHandler::class;
protected $sutRepo = 'LocalAuthority';
protected $qryClass = QryClass::class;
protected $repoClass = LocalAuthorityRepo::class;
protected $entityClass = LocalAuthorityEntity::class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Dvsa\OlcsTest\Api\Entity\LocalAuthority;

use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as Entity;
use Dvsa\OlcsTest\Api\Entity\Abstracts\EntityTester;

/**
* Local Authority Entity Unit Tests
*/
class LocalAuthorityEntityTest extends EntityTester
{
/**
* Define the entity to test
*
* @var string
*/
protected $entityClass = Entity::class;

public function testUpdate()
{
$description = 'some lta name';
$emailAddress = '[email protected]';
$entity = new Entity();
$entity->update($description, $emailAddress);
$this->assertEquals($description, $entity->getDescription());
$this->assertEquals($emailAddress, $entity->getEmailAddress());
}
}
Loading