Skip to content

Commit

Permalink
Add created_at field to attachments model (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjenMiedema authored Jun 4, 2024
1 parent b463a33 commit 24ebbab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/2.0.0.
### Added

- Added changelog and readme files
- `created_at` field to attachments database table and model

## [1.5.4] - 2024-02-14

Expand Down
15 changes: 15 additions & 0 deletions src/Api/Data/AttachmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

namespace JcElectronics\ExactOrders\Api\Data;

use DateTime;

interface AttachmentInterface
{
public const KEY_ID = 'attachment_id',
KEY_FILE_NAME = 'file',
KEY_FILE_CONTENT = 'file_content',
KEY_ENTITY_ID = 'entity_id',
KEY_ENTITY_TYPE_ID = 'entity_type_id',
KEY_CREATED_AT = 'created_at',
ENTITY_TYPE_INVOICE = 'invoice',
ENTITY_TYPE_ORDER = 'order';

Expand Down Expand Up @@ -78,4 +81,16 @@ public function getFileContent(): ?string;
* @return self
*/
public function setFileContent(string $fileContent): self;

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

/**
* @param DateTime $createdAt
*
* @return self
*/
public function setCreatedAt(DateTime $createdAt): self;
}
12 changes: 12 additions & 0 deletions src/Model/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace JcElectronics\ExactOrders\Model;

use DateTime;
use DateTimeInterface;
use JcElectronics\ExactOrders\Api\Data\AttachmentInterface;
use JcElectronics\ExactOrders\Model\ResourceModel\Attachment as AttachmentResourceModel;
use Magento\Framework\DataObject\IdentityInterface;
Expand Down Expand Up @@ -78,6 +80,16 @@ public function setFileContent(string $fileContent): self
return $this;
}

public function getCreatedAt(): DateTime
{
return new DateTime($this->_getData(self::KEY_CREATED_AT));
}

public function setCreatedAt(DateTime $createdAt): self
{
return $this->setData(self::KEY_CREATED_AT, $createdAt->format('Y-m-d H:i:s'));
}

private function normalizeFilename(string $fileName): string
{
$pathInfo = pathinfo($fileName);
Expand Down
1 change: 1 addition & 0 deletions src/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<column xsi:type="int" name="entity_id" unsigned="true" nullable="false" comment="Entity ID"/>
<column xsi:type="varchar" name="entity_type_id" length="20" nullable="false" comment="Entity Type ID"/>
<column xsi:type="varchar" name="file" nullable="false" comment="File Name"/>
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>

<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="attachment_id"/>
Expand Down
3 changes: 2 additions & 1 deletion src/etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"attachment_id": true,
"entity_id": true,
"entity_type_id": true,
"file": true
"file": true,
"created_at": true
},
"constraint": {
"PRIMARY": true,
Expand Down

0 comments on commit 24ebbab

Please sign in to comment.