mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Expand API for attachments.
This commit is contained in:
@@ -28,6 +28,7 @@ use FireflyIII\Models\Attachment;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
|
||||
/**
|
||||
* Class AttachmentTransformer
|
||||
@@ -39,13 +40,13 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['user'];
|
||||
protected $availableIncludes = ['user','notes'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['user'];
|
||||
protected $defaultIncludes = ['user','notes'];
|
||||
|
||||
/** @var ParameterBag */
|
||||
protected $parameters;
|
||||
@@ -76,6 +77,20 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
return $this->item($attachment->user, new UserTransformer($this->parameters), 'user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach the notes.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeNotes(Attachment $attachment): FractalCollection
|
||||
{
|
||||
return $this->collection($attachment->notes, new NoteTransformer($this->parameters), 'notes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attachment.
|
||||
*
|
||||
@@ -92,11 +107,11 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
'attachable_type' => $attachment->attachable_type,
|
||||
'md5' => $attachment->md5,
|
||||
'filename' => $attachment->filename,
|
||||
'download_uri' => route('api.v1.attachments.download', [$attachment->id]),
|
||||
'upload_uri' => route('api.v1.attachments.upload', [$attachment->id]),
|
||||
'title' => $attachment->title,
|
||||
'description' => $attachment->description,
|
||||
'notes' => $attachment->notes,
|
||||
'mime' => $attachment->mime,
|
||||
'size' => $attachment->size,
|
||||
'size' => (int)$attachment->size,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
||||
Reference in New Issue
Block a user