Align notes with object, not separate.

This commit is contained in:
James Cole
2018-09-27 07:43:30 +02:00
parent 214c7a6f3e
commit 2c2814c998
2 changed files with 21 additions and 37 deletions

View File

@@ -44,17 +44,20 @@ class BillTransformer extends TransformerAbstract
*
* @var array
*/
protected $availableIncludes = ['attachments', 'transactions', 'user', 'notes', 'rules'];
protected $availableIncludes = ['attachments', 'transactions', 'user', 'rules'];
/**
* List of resources to automatically include
*
* @var array
*/
protected $defaultIncludes = ['notes', 'rules'];
protected $defaultIncludes = ['rules'];
/** @var ParameterBag */
protected $parameters;
/** @var BillRepositoryInterface */
private $repository;
/**
* BillTransformer constructor.
*
@@ -65,6 +68,7 @@ class BillTransformer extends TransformerAbstract
public function __construct(ParameterBag $parameters)
{
$this->parameters = $parameters;
$this->repository = app(BillRepositoryInterface::class);
}
/**
@@ -82,20 +86,6 @@ class BillTransformer extends TransformerAbstract
return $this->collection($attachments, new AttachmentTransformer($this->parameters), 'attachments');
}
/**
* Attach the notes.
*
* @codeCoverageIgnore
*
* @param Bill $bill
*
* @return FractalCollection
*/
public function includeNotes(Bill $bill): FractalCollection
{
return $this->collection($bill->notes, new NoteTransformer($this->parameters), 'notes');
}
/**
* Attach the rules.
*
@@ -107,11 +97,9 @@ class BillTransformer extends TransformerAbstract
*/
public function includeRules(Bill $bill): FractalCollection
{
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->setUser($bill->user);
$this->repository->setUser($bill->user);
// add info about rules:
$rules = $repository->getRulesForBill($bill);
$rules = $this->repository->getRulesForBill($bill);
return $this->collection($rules, new RuleTransformer($this->parameters), 'rules');
}
@@ -167,7 +155,8 @@ class BillTransformer extends TransformerAbstract
{
$paidData = $this->paidData($bill);
$payDates = $this->payDates($bill);
$data = [
$this->repository->setUser($bill->user);
$data = [
'id' => (int)$bill->id,
'updated_at' => $bill->updated_at->toAtomString(),
'created_at' => $bill->created_at->toAtomString(),
@@ -184,6 +173,7 @@ class BillTransformer extends TransformerAbstract
'active' => $bill->active,
'attachments_count' => $bill->attachments()->count(),
'pay_dates' => $payDates,
'notes' => $this->repository->getNoteText($bill),
'paid_dates' => $paidData['paid_dates'],
'next_expected_match' => $paidData['next_expected_match'],
'links' => [