mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand all test models.
This commit is contained in:
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
|
||||
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
@@ -46,15 +45,19 @@ class StoreRequest extends FormRequest
|
||||
public function getAll(): array
|
||||
{
|
||||
$active = true;
|
||||
|
||||
$order = 31337;
|
||||
if (null !== $this->get('active')) {
|
||||
$active = $this->boolean('active');
|
||||
}
|
||||
if (null !== $this->get('order')) {
|
||||
$order = $this->integer('order');
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $this->string('title'),
|
||||
'description' => $this->string('description'),
|
||||
'active' => $active,
|
||||
'order' => $order,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
@@ -94,7 +93,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
/** @var TransactionJournalLink $existing */
|
||||
$existing = $this->route()->parameter('journalLink');
|
||||
$data = $validator->getData();
|
||||
$data = $validator->getData();
|
||||
/** @var LinkTypeRepositoryInterface $repository */
|
||||
$repository = app(LinkTypeRepositoryInterface::class);
|
||||
$repository->setUser(auth()->user());
|
||||
@@ -107,7 +106,13 @@ class UpdateRequest extends FormRequest
|
||||
$outwardId = $data['outward_id'] ?? $existing->destination_id;
|
||||
$inward = $journalRepos->findNull((int)$inwardId);
|
||||
$outward = $journalRepos->findNull((int)$outwardId);
|
||||
if($inward->id === $outward->id) {
|
||||
if (null === $inward) {
|
||||
$inward = $existing->source;
|
||||
}
|
||||
if (null === $outward) {
|
||||
$outward = $existing->destination;
|
||||
}
|
||||
if ($inward->id === $outward->id) {
|
||||
$validator->errors()->add('inward_id', 'Inward ID must be different from outward ID.');
|
||||
$validator->errors()->add('outward_id', 'Inward ID must be different from outward ID.');
|
||||
}
|
||||
@@ -115,14 +120,14 @@ class UpdateRequest extends FormRequest
|
||||
if (null === $inward) {
|
||||
$validator->errors()->add('inward_id', 'This is not a valid inward journal.');
|
||||
}
|
||||
if(null === $outward) {
|
||||
if (null === $outward) {
|
||||
$validator->errors()->add('inward_id', 'This is not a valid outward journal.');
|
||||
}
|
||||
$inDB =$repository->findSpecificLink($existing->linkType, $inward, $outward);
|
||||
if(null === $inDB) {
|
||||
$inDB = $repository->findSpecificLink($existing->linkType, $inward, $outward);
|
||||
if (null === $inDB) {
|
||||
return;
|
||||
}
|
||||
if($inDB->id !== $existing->id) {
|
||||
if ($inDB->id !== $existing->id) {
|
||||
$validator->errors()->add('outward_id', 'Already have a link between inward and outward.');
|
||||
$validator->errors()->add('inward_id', 'Already have a link between inward and outward.');
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function findLink(TransactionJournal $one, TransactionJournal $two): bool
|
||||
{
|
||||
Log::debug(sprintf('Now in findLink(%d, %d)', $one->id, $two->id));
|
||||
$count = TransactionJournalLink::whereDestinationId($one->id)->whereSourceId($two->id)->count();
|
||||
$opposingCount = TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->count();
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
++$rule->order;
|
||||
$rule->save();
|
||||
$this->resetRulesInGroupOrder($rule->ruleGroup);
|
||||
$this->resetRuleOrder($rule->ruleGroup);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
--$rule->order;
|
||||
$rule->save();
|
||||
$this->resetRulesInGroupOrder($rule->ruleGroup);
|
||||
$this->resetRuleOrder($rule->ruleGroup);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -365,7 +365,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$ruleGroup->rules()->withTrashed()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ interface RuleRepositoryInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool;
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
|
||||
@@ -89,9 +89,9 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
|
||||
$ruleGroup->delete();
|
||||
|
||||
$this->resetRuleGroupOrder();
|
||||
$this->resetOrder();
|
||||
if (null !== $moveTo) {
|
||||
$this->resetRulesInGroupOrder($moveTo);
|
||||
$this->resetRuleOrder($moveTo);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -324,21 +324,25 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleGroupOrder(): bool
|
||||
public function resetOrder(): bool
|
||||
{
|
||||
$this->user->ruleGroups()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||
$this->user->ruleGroups()->whereNotNull('deleted_at');
|
||||
|
||||
$set = $this->user
|
||||
->ruleGroups()
|
||||
->orderBy('order', 'ASC')->get();
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->get();
|
||||
$count = 1;
|
||||
/** @var RuleGroup $entry */
|
||||
foreach ($set as $entry) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
if ($entry->order !== $count) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
// also update rules in group.
|
||||
$this->resetRulesInGroupOrder($entry);
|
||||
$this->resetRuleOrder($entry);
|
||||
|
||||
++$count;
|
||||
}
|
||||
@@ -351,19 +355,21 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$ruleGroup->rules()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||
|
||||
$set = $ruleGroup->rules()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->orderBy('updated_at', 'DESC')
|
||||
->get();
|
||||
->get(['rules.*']);
|
||||
$count = 1;
|
||||
/** @var Rule $entry */
|
||||
foreach ($set as $entry) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
if ($entry->order !== $count) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
@@ -400,19 +406,18 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): RuleGroup
|
||||
{
|
||||
$order = $this->getHighestOrderRuleGroup();
|
||||
|
||||
$newRuleGroup = new RuleGroup(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'title' => $data['title'],
|
||||
'description' => $data['description'],
|
||||
'order' => $order + 1,
|
||||
'order' => 31337,
|
||||
'active' => $data['active'],
|
||||
]
|
||||
);
|
||||
$newRuleGroup->save();
|
||||
$this->resetRuleGroupOrder();
|
||||
$this->resetOrder();
|
||||
$this->setOrder($newRuleGroup, $data['order']);
|
||||
|
||||
return $newRuleGroup;
|
||||
}
|
||||
@@ -437,11 +442,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
// order
|
||||
if (array_key_exists('order', $data) && $ruleGroup->order !== $data['order']) {
|
||||
$this->correctRuleGroupOrder();
|
||||
$max = $this->maxOrder();
|
||||
// TODO also for bills and accounts:
|
||||
$data['order'] = $data['order'] > $max ? $max : $data['order'];
|
||||
$ruleGroup = $this->updateOrder($ruleGroup, $ruleGroup->order, $data['order']);
|
||||
$this->resetOrder();
|
||||
$this->setOrder($ruleGroup, (int)$data['order']);
|
||||
}
|
||||
|
||||
$ruleGroup->save();
|
||||
@@ -449,26 +451,30 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return $ruleGroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function updateOrder(RuleGroup $ruleGroup, int $oldOrder, int $newOrder): RuleGroup
|
||||
public function setOrder(RuleGroup $ruleGroup, int $newOrder): void
|
||||
{
|
||||
$oldOrder = (int)$ruleGroup->order;
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->ruleGroups()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)
|
||||
$this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder)
|
||||
->where('rule_groups.id', '!=', $ruleGroup->id)
|
||||
->decrement('rule_groups.order', 1);
|
||||
$ruleGroup->order = $newOrder;
|
||||
$ruleGroup->save();
|
||||
}
|
||||
if ($newOrder < $oldOrder) {
|
||||
$this->user->ruleGroups()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)
|
||||
->where('rule_groups.id', '!=', $ruleGroup->id)
|
||||
->increment('rule_groups.order', 1);
|
||||
->decrement('order', 1);
|
||||
$ruleGroup->order = $newOrder;
|
||||
Log::debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
|
||||
$ruleGroup->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return $ruleGroup;
|
||||
$this->user->ruleGroups()->where('rule_groups.order', '>=', $newOrder)->where('rule_groups.order', '<', $oldOrder)
|
||||
->where('rule_groups.id', '!=', $ruleGroup->id)
|
||||
->increment('order', 1);
|
||||
$ruleGroup->order = $newOrder;
|
||||
Log::debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
|
||||
$ruleGroup->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,14 +145,20 @@ interface RuleGroupRepositoryInterface
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleGroupOrder(): bool;
|
||||
public function resetOrder(): bool;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRulesInGroupOrder(RuleGroup $ruleGroup): bool;
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $newOrder
|
||||
*/
|
||||
public function setOrder(RuleGroup $ruleGroup, int $newOrder): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
@@ -181,14 +187,4 @@ interface RuleGroupRepositoryInterface
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function update(RuleGroup $ruleGroup, array $data): RuleGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $oldOrder
|
||||
* @param int $newOrder
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function updateOrder(RuleGroup $ruleGroup, int $oldOrder, int $newOrder): RuleGroup;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class TagTransformer extends AbstractTransformer
|
||||
if (null !== $location) {
|
||||
$latitude = $location->latitude;
|
||||
$longitude = $location->longitude;
|
||||
$zoomLevel = $location->zoom_level;
|
||||
$zoomLevel = (int)$location->zoom_level;
|
||||
}
|
||||
return [
|
||||
'id' => (int)$tag->id,
|
||||
|
||||
Reference in New Issue
Block a user