Files

74 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2024-12-22 13:19:23 +01:00
<?php
2024-12-22 13:19:23 +01:00
/*
2025-01-26 10:09:09 +01:00
* StoreRequest.php
* Copyright (c) 2025 james@firefly-iii.org.
2024-12-22 13:19:23 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
2025-01-26 10:09:09 +01:00
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
2024-12-22 13:19:23 +01:00
use Carbon\Carbon;
use FireflyIII\Models\TransactionCurrency;
2025-09-07 14:49:49 +02:00
use FireflyIII\Support\Facades\Amount;
2024-12-22 13:19:23 +01:00
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
2026-03-07 06:31:14 +01:00
2026-03-07 06:15:55 +01:00
protected array $acceptedRoles = [];
2024-12-22 13:19:23 +01:00
public function getDate(): ?Carbon
{
return $this->getCarbonDate('date');
}
2025-05-04 17:41:26 +02:00
public function getFromCurrency(): TransactionCurrency
2024-12-22 13:19:23 +01:00
{
2025-09-07 14:49:49 +02:00
return Amount::getTransactionCurrencyByCode((string) $this->get('from'));
2024-12-22 13:19:23 +01:00
}
2025-05-04 17:41:26 +02:00
public function getRate(): string
{
2025-05-04 17:41:26 +02:00
return (string) $this->get('rate');
2024-12-22 13:19:23 +01:00
}
public function getToCurrency(): TransactionCurrency
{
2025-09-07 14:49:49 +02:00
return Amount::getTransactionCurrencyByCode((string) $this->get('to'));
2024-12-22 13:19:23 +01:00
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
2026-05-21 06:31:24 +02:00
'date' => ['required', 'date', 'after:1970-01-02', 'before:2038-01-17'],
'rate' => ['required', 'numeric', 'gt:0'],
'from' => ['required', 'exists:transaction_currencies,code'],
'to' => ['required', 'exists:transaction_currencies,code'],
2024-12-22 13:19:23 +01:00
];
}
}