Skip to content

Commit

Permalink
init:create repository
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloargentiero committed Aug 9, 2022
0 parents commit c385d6e
Show file tree
Hide file tree
Showing 17 changed files with 1,072 additions and 0 deletions.
111 changes: 111 additions & 0 deletions Api/Data/EntityInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/*
* Copyright © Ghost Unicorns snc. All rights reserved.
* See LICENSE for license details.
*/

declare(strict_types=1);

namespace GhostUnicorns\CrtEntity\Api\Data;

use DateTime;
use Exception;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\DataObject;

interface EntityInterface extends ExtensibleDataInterface
{
/**
* @return int
*/
public function getActivityId(): int;

/**
* @param int $activityId
* @return void
*/
public function setActivityId(int $activityId);

/**
* @return string
*/
public function getType(): string;

/**
* @param string $type
* @return void
*/
public function setType(string $type);

/**
* @return string
*/
public function getIdentifier(): string;

/**
* @param string $identifier
* @return void
*/
public function setIdentifier(string $identifier);

/**
* @return string
*/
public function getDataOriginal(): string;

/**
* @param string $value
* @return void
*/
public function setDataOriginal(string $value);

/**
* @return string
*/
public function getDataRefined(): string;

/**
* @param string|null $value
* @return void
*/
public function setDataRefined(?string $value);

/**
* @return DataObject
*/
public function getExtra(): DataObject;

/**
* @param DataObject $value
* @return void
*/
public function setExtra(DataObject $value);

/**
* @param array $value
* @return void
*/
public function addExtraArray(array $value);

/**
* @return DateTime
* @throws Exception
*/
public function getCreatedAt(): DateTime;

/**
* @return DateTime
* @throws Exception
*/
public function getUpdatedAt(): DateTime;

/**
* @return bool
*/
public function isSkip(): bool;

/**
* @return void
*/
public function skip();
}
25 changes: 25 additions & 0 deletions Api/Data/EntitySearchResultInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* Copyright © Ghost Unicorns snc. All rights reserved.
* See LICENSE for license details.
*/

declare(strict_types=1);

namespace GhostUnicorns\CrtEntity\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

interface EntitySearchResultInterface extends SearchResultsInterface
{
/**
* @return EntityInterface[]
*/
public function getItems();

/**
* @param EntityInterface[] $items
* @return void
*/
public function setItems(array $items);
}
98 changes: 98 additions & 0 deletions Api/EntityRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/*
* Copyright © Ghost Unicorns snc. All rights reserved.
* See LICENSE for license details.
*/

declare(strict_types=1);

namespace GhostUnicorns\CrtEntity\Api;

use Exception;
use GhostUnicorns\CrtEntity\Api\Data\EntityInterface;
use GhostUnicorns\CrtEntity\Api\Data\EntitySearchResultInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Exception\NoSuchEntityException;

interface EntityRepositoryInterface
{
/**
* @param int $id
* @return EntityInterface
* @throws NoSuchEntityException
*/
public function getById(int $id): EntityInterface;

/**
* @param EntityInterface $entity
* @return EntityInterface
*/
public function save(EntityInterface $entity);

/**
* @param EntityInterface $entity
* @return void
*/
public function delete(EntityInterface $entity);

/**
* @param SearchCriteriaInterface $searchCriteria
* @return EntitySearchResultInterface
*/
public function getList(SearchCriteriaInterface $searchCriteria): EntitySearchResultInterface;

/**
* @param int $activityId
* @return EntityInterface[]
* @throws Exception
*/
public function getAllByActivityId(int $activityId): array;

/**
* @param int $activityId
* @param string $identifier
* @return EntityInterface[]
* @throws Exception
*/
public function getAllByActivityIdAndIdentifier(int $activityId, string $identifier): array;

/**
* @param int $activityId
* @param string $identifier
* @param string $type
* @return EntityInterface
* @throws Exception
*/
public function getByActivityIdAndIdentifierAndType(
int $activityId,
string $identifier,
string $type
): EntityInterface;

/**
* @param int $activityId
* @return array
* @throws Exception
*/
public function getAllByActivityIdGroupedByIdentifier(int $activityId): array;

/**
* @param int $activityId
* @return array
* @throws Exception
*/
public function getAllIdentifiersByActivityId(int $activityId): array;

/**
* @param int $activityId
* @param string $identifier
* @return array
*/
public function getAllByActivityIdAndIdentifierGroupedByIdentifier(int $activityId, string $identifier): array;

/**
* @param int $activityId
* @return array
*/
public function getAllDataRefinedByActivityIdGroupedByIdentifier(int $activityId): array;
}
Empty file added LICENSE
Empty file.
45 changes: 45 additions & 0 deletions Model/AddExtraDataToEntitiesByActivityId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* Copyright © Ghost Unicorns snc. All rights reserved.
* See LICENSE for license details.
*/

declare(strict_types=1);

namespace GhostUnicorns\CrtEntity\Model;

use Exception;
use GhostUnicorns\CrtEntity\Api\EntityRepositoryInterface;

class AddExtraDataToEntitiesByActivityId
{
/**
* @var EntityRepositoryInterface
*/
private $entityRepository;

/**
* @param EntityRepositoryInterface $entityRepository
*/
public function __construct(
EntityRepositoryInterface $entityRepository
) {
$this->entityRepository = $entityRepository;
}

/**
* @param int $activityId
* @param string $identifier
* @param array $extraData
* @throws Exception
*/
public function execute(int $activityId, string $identifier, array $extraData)
{
$entities = $this->entityRepository->getAllByActivityIdAndIdentifier($activityId, $identifier);

foreach ($entities as $entity) {
$entity->addExtraArray($extraData);
$this->entityRepository->save($entity);
}
}
}
51 changes: 51 additions & 0 deletions Model/ClearDataRefinedByActivityId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* Copyright © Ghost Unicorns snc. All rights reserved.
* See LICENSE for license details.
*/

declare(strict_types=1);

namespace GhostUnicorns\CrtEntity\Model;

use GhostUnicorns\CrtEntity\Api\EntityRepositoryInterface;
use GhostUnicorns\CrtEntity\Model\ResourceModel\EntityResourceModel;
use Magento\Framework\Exception\AlreadyExistsException;

class ClearDataRefinedByActivityId
{
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $entityRepository;

/**
* @var EntityResourceModel
*/
private $entityResourceModel;

/**
* @param EntityRepositoryInterface $entityRepository
* @param EntityResourceModel $entityResourceModel
*/
public function __construct(
EntityRepositoryInterface $entityRepository,
EntityResourceModel $entityResourceModel
) {
$this->entityRepository = $entityRepository;
$this->entityResourceModel = $entityResourceModel;
}

/**
* @param int $activityId
* @throws AlreadyExistsException
*/
public function execute(int $activityId)
{
$entities = $this->entityRepository->getAllByActivityId($activityId);
foreach ($entities as $entity) {
$entity->setDataRefined(null);
$this->entityResourceModel->save($entity);
}
}
}
Loading

0 comments on commit c385d6e

Please sign in to comment.