Skip to content

Commit

Permalink
WIP #24 design SC
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Nov 20, 2019
1 parent 289f98b commit ecc2c23
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 3 deletions.
69 changes: 69 additions & 0 deletions Api/AgreementRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api;

use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Opengento\Gdpr\Api\Data\AgreementInterface;
use Opengento\Gdpr\Api\Data\AgreementSearchResultsInterface;

/**
* @api
*/
interface AgreementRepositoryInterface
{
/**
* Save agreement
*
* @param AgreementInterface $agreement
* @return AgreementInterface
* @throws CouldNotSaveException
*/
public function save(AgreementInterface $agreement): AgreementInterface;

/**
* Retrieve agreement by ID
*
* @param int $agreementId
* @return AgreementInterface
* @throws NoSuchEntityException
*/
public function getById(int $agreementId): AgreementInterface;

/**
* Retrieve agreement by identifier and scope
*
* @param string $identifier
* @param int $storeId
* @return AgreementInterface
* @throws NoSuchEntityException
*/
public function getByIdentifier(string $identifier, int $storeId): AgreementInterface;

/**
* Retrieve agreement list by search filter criteria
*
* @param SearchCriteriaInterface $searchCriteria
* @return AgreementSearchResultsInterface
* @throws LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria): AgreementSearchResultsInterface;

/**
* Delete agreement
*
* @param AgreementInterface $agreement
* @return bool true on success
* @throws NoSuchEntityException
* @throws CouldNotDeleteException
*/
public function delete(AgreementInterface $agreement): bool;
}
55 changes: 55 additions & 0 deletions Api/Data/AgreementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api\Data;

use Magento\Framework\Api\ExtensibleDataInterface;

/**
* @api
*/
interface AgreementInterface extends ExtensibleDataInterface
{
/**
* Constants for fields keys
*/
public const ID = 'agreement_id';
public const IDENTIFIER = 'identifier';
public const IS_ACTIVE = 'is_active';
public const IS_MANDATORY = 'is_mandatory';
public const TITLE = 'title';
public const LABEL = 'label';
public const CONTENT = 'content';

public function getAgreementId(): int;

public function setAgreementId(int $agreementId): AgreementInterface;

public function getIdentifier(): string;

public function setIdentifier(string $identifier): AgreementInterface;

public function getIsActive(): bool;

public function setIsActive(bool $isActive): AgreementInterface;

public function getIsMandatory(): bool;

public function setIsMandatory(bool $isMandatory): AgreementInterface;

public function getTitle(): string;

public function setTitle(string $title): AgreementInterface;

public function getLabel(): string;

public function setLabel(string $label): AgreementInterface;

public function getContent(): string;

public function setContent(string $content): AgreementInterface;
}
31 changes: 31 additions & 0 deletions Api/Data/AgreementSearchResultsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

/**
* @api
*/
interface AgreementSearchResultsInterface extends SearchResultsInterface
{
/**
* Retrieve the agreement entities list
*
* @return AgreementInterface[]
*/
public function getItems(): array;

/**
* Set the agreement entity list
*
* @param AgreementInterface[] $items
* @return AgreementSearchResultsInterface
*/
public function setItems(array $items): AgreementSearchResultsInterface;
}
45 changes: 45 additions & 0 deletions Api/Data/ConsentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api\Data;

use Magento\Framework\Api\ExtensibleDataInterface;

/**
* @api
*/
interface ConsentInterface extends ExtensibleDataInterface
{
/**
* Constants for fields keys
*/
public const ID = 'consent_id';
public const AGREEMENT_IDENTIFIER = 'agreement_identifier';
public const IS_APPROVED = 'is_approved';
public const IS_OUTDATED = 'is_outdated'; //todo when it's outdated or the agreement has been modified
public const SUBMITTED_AT = 'submitted_at';

public function getConsentId(): int;

public function setConsentId(int $consentId): ConsentInterface;

public function getAgreementIdentifier(): string;

public function setAgreementIdentifier(string $agreementIdentifier): ConsentInterface;

public function isApproved(): bool;

public function setIsApproved(bool $isApproved): ConsentInterface;

public function isOutDated(): bool;

public function setIsOutDated(bool $isOutDated): ConsentInterface;

public function getSubmittedAt(): string;

public function setSubmittedAt(string $submittedAt): ConsentInterface;
}
64 changes: 64 additions & 0 deletions Model/AbstractConsent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Model;

use Magento\Framework\Model\AbstractExtensibleModel;
use Opengento\Gdpr\Api\Data\ConsentInterface;

abstract class AbstractConsent extends AbstractExtensibleModel implements ConsentInterface
{
public function getConsentId(): int
{
return (int) $this->_getData(self::ID);
}

public function setConsentId(int $consentId): ConsentInterface
{
return $this->setData(self::ID, $consentId);
}

public function getAgreementIdentifier(): string
{
return (string) $this->_getData(self::AGREEMENT_IDENTIFIER);
}

public function setAgreementIdentifier(string $agreementIdentifier): ConsentInterface
{
return $this->setData(self::AGREEMENT_IDENTIFIER, $agreementIdentifier);
}

public function isApproved(): bool
{
return (bool) $this->_getData(self::IS_APPROVED);
}

public function setIsApproved(bool $isApproved): ConsentInterface
{
return $this->setData(self::IS_APPROVED, $isApproved);
}

public function isOutDated(): bool
{
return (bool) $this->_getData(self::IS_OUTDATED);
}

public function setIsOutDated(bool $isOutDated): ConsentInterface
{
return $this->setData(self::IS_OUTDATED, $isOutDated);
}

public function getSubmittedAt(): string
{
return (string) $this->_getData(self::SUBMITTED_AT);
}

public function setSubmittedAt(string $submittedAt): ConsentInterface
{
return $this->setData(self::SUBMITTED_AT, $submittedAt);
}
}
38 changes: 35 additions & 3 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="opengento_gdpr_erase_entity" resource="default" engine="innodb" comment="Erase Entity">
<column xsi:type="smallint" name="erase_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Erase ID"/>
<column xsi:type="int" name="erase_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Erase ID"/>
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" comment="Entity ID"/>
<column xsi:type="varchar" name="entity_type" length="255" nullable="false" comment="Entity Type"/>
<column xsi:type="timestamp" name="scheduled_at" nullable="false" comment="Scheduled At"/>
Expand All @@ -26,7 +26,7 @@
</index>
</table>
<table name="opengento_gdpr_export_entity" resource="default" engine="innodb" comment="Export Entity">
<column xsi:type="smallint" name="export_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Export ID"/>
<column xsi:type="int" name="export_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Export ID"/>
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" comment="Entity ID"/>
<column xsi:type="varchar" name="entity_type" length="255" nullable="false" comment="Entity Type"/>
<column xsi:type="varchar" name="file_name" length="255" nullable="false" comment="File Name"/>
Expand All @@ -45,7 +45,7 @@
</index>
</table>
<table name="opengento_gdpr_action_entity" resource="default" engine="innodb" comment="Action Entity">
<column xsi:type="smallint" name="action_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Export ID"/>
<column xsi:type="int" name="action_id" padding="11" unsigned="true" nullable="false" identity="true" comment="Export ID"/>
<column xsi:type="varchar" name="type" length="255" nullable="false" comment="Type"/>
<column xsi:type="text" name="performed_from" nullable="false" comment="Performed From"/>
<column xsi:type="text" name="performed_by" nullable="true" comment="Performed By"/>
Expand All @@ -63,4 +63,36 @@
<column name="state"/>
</index>
</table>
<table name="opengento_gdpr_agreement" resource="default" engine="innodb" comment="Agreement">
<column xsi:type="int" name="agreement_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Agreement Id"/>
<column xsi:type="varchar" name="identifier" nullable="true" length="255" comment="Identifier"/>
<column xsi:type="smallint" name="is_active" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Is Active"/>
<column xsi:type="smallint" name="is_mandatory" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Is Mandatory"/>
<column xsi:type="text" name="title" nullable="true" comment="Title"/>
<column xsi:type="text" name="label" nullable="true" comment="Label"/>
<column xsi:type="text" name="content" nullable="true" comment="Content"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="agreement_id"/>
</constraint>
</table>
<table name="opengento_gdpr_agreement_store" resource="default" engine="innodb" comment="Checkout Agreement Store">
<column xsi:type="int" name="agreement_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Agreement Id"/>
<column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" comment="Store Id"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="agreement_id"/>
<column name="store_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="OPENGENTO_GDPR_AGREEMENT_STORE_AGRT_ID_OPENGENTO_GDPR_AGREEMENT_AGREEMENT_ID" table="opengento_gdpr_agreement_store" column="agreement_id" referenceTable="opengento_gdpr_agreement" referenceColumn="agreement_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="OPENGENTO_GDPR_AGREEMENT_STORE_STORE_ID_STORE_STORE_ID" table="opengento_gdpr_agreement_store" column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
</table>
<table name="opengento_gdpr_consent" resource="default" engine="innodb" comment="Consent">
<column xsi:type="int" name="consent_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Consent Id"/>
<column xsi:type="varchar" name="agreement_identifier" nullable="true" length="255" comment="Agreement Identifier"/>
<column xsi:type="smallint" name="is_approved" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Is Approved"/>
<column xsi:type="smallint" name="is_outdated" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Is Outdated"/>
<column xsi:type="timestamp" name="submitted_at" nullable="false" comment="Submitted At"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="consent_id"/>
</constraint>
</table>
</schema>

0 comments on commit ecc2c23

Please sign in to comment.