2018-02-04 08:57:35 -06:00
|
|
|
<?php
|
|
|
|
/**
|
2018-02-06 00:49:56 -06:00
|
|
|
* AttachmentTransformer.php
|
2020-02-16 06:57:18 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-02-04 08:57:35 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-02-04 08:57:35 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-02-04 08:57:35 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-02-04 08:57:35 -06:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:37:26 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-02-04 08:57:35 -06:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-02-04 08:57:35 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Transformers;
|
2021-09-18 03:26:12 -05:00
|
|
|
|
2018-02-06 00:49:56 -06:00
|
|
|
use FireflyIII\Models\Attachment;
|
2018-09-27 00:43:30 -05:00
|
|
|
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
2018-02-04 08:57:35 -06:00
|
|
|
|
|
|
|
/**
|
2018-02-06 00:49:56 -06:00
|
|
|
* Class AttachmentTransformer
|
2018-02-04 08:57:35 -06:00
|
|
|
*/
|
2018-12-16 06:55:19 -06:00
|
|
|
class AttachmentTransformer extends AbstractTransformer
|
2018-02-04 08:57:35 -06:00
|
|
|
{
|
2020-07-31 08:12:26 -05:00
|
|
|
private AttachmentRepositoryInterface $repository;
|
2018-09-27 00:43:30 -05:00
|
|
|
|
2018-02-11 13:45:33 -06:00
|
|
|
/**
|
|
|
|
* BillTransformer constructor.
|
|
|
|
*/
|
2018-12-16 06:55:19 -06:00
|
|
|
public function __construct()
|
2018-02-11 13:45:33 -06:00
|
|
|
{
|
2018-09-27 00:43:30 -05:00
|
|
|
$this->repository = app(AttachmentRepositoryInterface::class);
|
2018-02-10 03:58:06 -06:00
|
|
|
}
|
|
|
|
|
2018-02-04 08:57:35 -06:00
|
|
|
/**
|
2018-02-16 15:47:08 -06:00
|
|
|
* Transform attachment.
|
2018-02-04 08:57:35 -06:00
|
|
|
*/
|
2018-02-06 00:49:56 -06:00
|
|
|
public function transform(Attachment $attachment): array
|
2018-02-04 08:57:35 -06:00
|
|
|
{
|
2018-09-27 00:43:30 -05:00
|
|
|
$this->repository->setUser($attachment->user);
|
|
|
|
|
2018-02-04 08:57:35 -06:00
|
|
|
return [
|
2022-12-29 12:42:26 -06:00
|
|
|
'id' => (string)$attachment->id,
|
2018-02-11 00:46:34 -06:00
|
|
|
'created_at' => $attachment->created_at->toAtomString(),
|
2018-12-12 13:30:25 -06:00
|
|
|
'updated_at' => $attachment->updated_at->toAtomString(),
|
2022-12-29 12:42:26 -06:00
|
|
|
'attachable_id' => (string)$attachment->attachable_id,
|
2024-06-15 09:16:40 -05:00
|
|
|
'attachable_type' => str_replace('FireflyIII\Models\\', '', $attachment->attachable_type),
|
2018-02-06 12:49:29 -06:00
|
|
|
'md5' => $attachment->md5,
|
|
|
|
'filename' => $attachment->filename,
|
2021-09-18 03:21:29 -05:00
|
|
|
'download_url' => route('api.v1.attachments.download', [$attachment->id]),
|
|
|
|
'upload_url' => route('api.v1.attachments.upload', [$attachment->id]),
|
2018-02-06 12:49:29 -06:00
|
|
|
'title' => $attachment->title,
|
2018-09-27 00:43:30 -05:00
|
|
|
'notes' => $this->repository->getNoteText($attachment),
|
2018-12-18 23:06:01 -06:00
|
|
|
'mime' => $attachment->mime,
|
2022-12-29 12:42:26 -06:00
|
|
|
'size' => (int)$attachment->size,
|
2018-02-07 04:20:24 -06:00
|
|
|
'links' => [
|
|
|
|
[
|
|
|
|
'rel' => 'self',
|
2023-12-20 12:35:52 -06:00
|
|
|
'uri' => '/attachment/'.$attachment->id,
|
2018-02-07 04:20:24 -06:00
|
|
|
],
|
2018-02-09 12:11:55 -06:00
|
|
|
],
|
2018-02-04 08:57:35 -06:00
|
|
|
];
|
|
|
|
}
|
2018-03-05 12:35:58 -06:00
|
|
|
}
|