Update rule group API

This commit is contained in:
James Cole 2018-12-07 07:49:16 +01:00
parent 3e84f9664f
commit b782316cc0
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 21 additions and 49 deletions

View File

@ -158,6 +158,7 @@ class RuleGroupController extends Controller
/**
* Update a rule group.
* TODO update order of rule group
*
* @param RuleGroupRequest $request
* @param RuleGroup $ruleGroup

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Rules\IsBoolean;
/**
@ -50,10 +51,18 @@ class RuleGroupRequest extends Request
*/
public function getAll(): array
{
if (null === $this->get('active')) {
$active = true;
}
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
return [
'title' => $this->string('title'),
'description' => $this->string('description'),
'active' => $this->boolean('active'),
'active' => $active,
];
}
@ -67,7 +76,7 @@ class RuleGroupRequest extends Request
$rules = [
'title' => 'required|between:1,100|uniqueObjectForUser:rule_groups,title',
'description' => 'between:1,5000|nullable',
'active' => 'required|boolean',
'active' => [new IsBoolean],
];
switch ($this->method()) {
default:

View File

@ -296,7 +296,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
'title' => $data['title'],
'description' => $data['description'],
'order' => $order + 1,
'active' => 1,
'active' => $data['active'],
]
);
$newRuleGroup->save();

View File

@ -24,8 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Transformers;
use FireflyIII\Models\RuleGroup;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use League\Fractal\TransformerAbstract;
use Symfony\Component\HttpFoundation\ParameterBag;
@ -34,19 +32,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
class RuleGroupTransformer extends TransformerAbstract
{
/**
* List of resources possible to include
*
* @var array
*/
protected $availableIncludes = ['user'];
/**
* List of resources to automatically include
*
* @var array
*/
protected $defaultIncludes = ['user'];
/** @var ParameterBag */
protected $parameters;
@ -62,29 +47,6 @@ class RuleGroupTransformer extends TransformerAbstract
$this->parameters = $parameters;
}
/**
* @param RuleGroup $ruleGroup
*
* @return FractalCollection
*/
public function includeRules(RuleGroup $ruleGroup): FractalCollection
{
return $this->collection($ruleGroup->rules, new RuleTransformer($this->parameters), 'rules');
}
/**
* Include the user.
*
* @param RuleGroup $ruleGroup
*
* @codeCoverageIgnore
* @return Item
*/
public function includeUser(RuleGroup $ruleGroup): Item
{
return $this->item($ruleGroup->user, new UserTransformer($this->parameters), 'users');
}
/**
* Transform the rule group
*
@ -95,14 +57,14 @@ class RuleGroupTransformer extends TransformerAbstract
public function transform(RuleGroup $ruleGroup): array
{
$data = [
'id' => (int)$ruleGroup->id,
'updated_at' => $ruleGroup->updated_at->toAtomString(),
'created_at' => $ruleGroup->created_at->toAtomString(),
'title' => $ruleGroup->title,
'text' => $ruleGroup->text,
'order' => $ruleGroup->order,
'active' => $ruleGroup->active,
'links' => [
'id' => (int)$ruleGroup->id,
'updated_at' => $ruleGroup->updated_at->toAtomString(),
'created_at' => $ruleGroup->created_at->toAtomString(),
'title' => $ruleGroup->title,
'description' => $ruleGroup->description,
'order' => $ruleGroup->order,
'active' => $ruleGroup->active,
'links' => [
[
'rel' => 'self',
'uri' => '/rule_groups/' . $ruleGroup->id,