mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 08:51:12 -06:00
Update rule group API
This commit is contained in:
parent
3e84f9664f
commit
b782316cc0
@ -158,6 +158,7 @@ class RuleGroupController extends Controller
|
||||
|
||||
/**
|
||||
* Update a rule group.
|
||||
* TODO update order of rule group
|
||||
*
|
||||
* @param RuleGroupRequest $request
|
||||
* @param RuleGroup $ruleGroup
|
||||
|
@ -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:
|
||||
|
@ -296,7 +296,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
'title' => $data['title'],
|
||||
'description' => $data['description'],
|
||||
'order' => $order + 1,
|
||||
'active' => 1,
|
||||
'active' => $data['active'],
|
||||
]
|
||||
);
|
||||
$newRuleGroup->save();
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user