Expand API for attachments.

This commit is contained in:
James Cole
2018-06-24 06:51:22 +02:00
parent 32b6ded008
commit ad6a9a7df7
28 changed files with 1290 additions and 59 deletions

View File

@@ -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',