Move stuff to request classes for #339

This commit is contained in:
James Cole
2016-10-23 12:10:22 +02:00
parent 83f48418f6
commit 9a30fbd05a
15 changed files with 129 additions and 91 deletions

View File

@@ -33,6 +33,17 @@ class CategoryFormRequest extends Request
return auth()->check();
}
/**
* @return array
*/
public function getCategoryData(): array
{
return [
'name' => trim($this->input('name')),
'user' => auth()->user()->id,
];
}
/**
* @return array
*/

View File

@@ -30,6 +30,16 @@ class ConfigurationRequest extends Request
return auth()->check() && auth()->user()->hasRole('owner');
}
/**
* @return array
*/
public function getConfigurationData(): array
{
return [
'single_user_mode' => intval($this->get('single_user_mode')) === 1,
];
}
/**
* @return array
*/

View File

@@ -13,6 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use Carbon\Carbon;
use Input;
/**
@@ -32,6 +33,21 @@ class PiggyBankFormRequest extends Request
return auth()->check();
}
/**
* @return array
*/
public function getPiggyBankData(): array
{
return [
'name' => trim($this->get('name')),
'startdate' => new Carbon,
'account_id' => intval($this->get('account_id')),
'targetamount' => round($this->get('targetamount'), 2),
'targetdate' => strlen($this->get('targetdate')) > 0 ? new Carbon($this->get('targetdate')) : null,
'note' => trim($this->get('note')),
];
}
/**
* @return array
*/

View File

@@ -33,6 +33,26 @@ class RuleFormRequest extends Request
return auth()->check();
}
/**
* @return array
*/
public function getRuleData(): array
{
return [
'title' => trim($this->get('title')),
'active' => intval($this->get('active')) == 1,
'trigger' => trim($this->get('trigger')),
'description' => trim($this->get('description')),
'rule-triggers' => $this->get('rule-trigger'),
'rule-trigger-values' => $this->get('rule-trigger-value'),
'rule-trigger-stop' => $this->get('rule-trigger-stop'),
'rule-actions' => $this->get('rule-action'),
'rule-action-values' => $this->get('rule-action-value'),
'rule-action-stop' => $this->get('rule-action-stop'),
'stop_processing' => intval($this->get('stop_processing')) === 1,
];
}
/**
* @return array
*/

View File

@@ -20,8 +20,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\RuleGroup;
use Input;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
/**
* Class RuleGroupFormRequest
@@ -40,15 +39,27 @@ class RuleGroupFormRequest extends Request
return auth()->check();
}
/**
* @return array
*/
public function getRuleGroupData(): array
{
return [
'title' => trim($this->input('title')),
'description' => trim($this->input('description')),
];
}
/**
* @return array
*/
public function rules()
{
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
if (RuleGroup::find(Input::get('id'))) {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval(Input::get('id'));
/** @var RuleGroupRepositoryInterface $repository */
$repository = app(RuleGroupRepositoryInterface::class, [auth()->user()]);
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval($this->get('id'));
}
return [