mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Fix currency exchange rates
This commit is contained in:
		| @@ -24,8 +24,11 @@ declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Api\V2\Request\Model\ExchangeRate\DestroyRequest; | ||||
| use FireflyIII\Api\V1\Controllers\Controller; | ||||
| use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\DestroyRequest; | ||||
| use FireflyIII\Enums\UserRoleEnum; | ||||
| use FireflyIII\Exceptions\ValidationException; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface; | ||||
| use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait; | ||||
| @@ -36,6 +39,8 @@ class DestroyController extends Controller | ||||
| { | ||||
|     use ValidatesUserGroupTrait; | ||||
| 
 | ||||
|     protected array $acceptedRoles = [UserRoleEnum::OWNER]; | ||||
| 
 | ||||
|     public const string RESOURCE_KEY = 'exchange-rates'; | ||||
| 
 | ||||
|     private ExchangeRateRepositoryInterface $repository; | ||||
| @@ -56,6 +61,9 @@ class DestroyController extends Controller | ||||
|     public function destroy(DestroyRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse | ||||
|     { | ||||
|         $date = $request->getDate(); | ||||
|         if(null === $date) { | ||||
|             throw new ValidationException('Date is required'); | ||||
|         } | ||||
|         $rate = $this->repository->getSpecificRateOnDate($from, $to, $date); | ||||
|         if (null === $rate) { | ||||
|             throw new NotFoundHttpException(); | ||||
| @@ -64,4 +72,11 @@ class DestroyController extends Controller | ||||
| 
 | ||||
|         return response()->json([], 204); | ||||
|     } | ||||
| 
 | ||||
|     public function destroySingle(CurrencyExchangeRate $exchangeRate): JsonResponse | ||||
|     { | ||||
|         $this->repository->deleteRate($exchangeRate); | ||||
| 
 | ||||
|         return response()->json([], 204); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -38,7 +38,7 @@ class IndexController extends Controller | ||||
| { | ||||
|     use ValidatesUserGroupTrait; | ||||
| 
 | ||||
|     public const string RESOURCE_KEY = 'exchange_rates'; | ||||
|     public const string RESOURCE_KEY = 'currency_exchange_rates'; | ||||
| 
 | ||||
|     private ExchangeRateRepositoryInterface $repository; | ||||
| 
 | ||||
| @@ -62,9 +62,6 @@ class IndexController extends Controller | ||||
|         $count       = $piggies->count(); | ||||
|         $piggies     = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); | ||||
|         $paginator   = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page')); | ||||
| 
 | ||||
|         var_dump('here we are'); | ||||
| 
 | ||||
|         $transformer = new ExchangeRateTransformer(); | ||||
|         $transformer->setParameters($this->parameters); // give params to transformer
 | ||||
| 
 | ||||
|   | ||||
| @@ -25,6 +25,7 @@ declare(strict_types=1); | ||||
| namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface; | ||||
| use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait; | ||||
| @@ -73,4 +74,15 @@ class ShowController extends Controller | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function showSingle(CurrencyExchangeRate $exchangeRate): JsonResponse | ||||
|     { | ||||
|         $transformer  = new ExchangeRateTransformer(); | ||||
|         $transformer->setParameters($this->parameters); | ||||
| 
 | ||||
|         return response() | ||||
|             ->api($this->jsonApiObject(self::RESOURCE_KEY, $exchangeRate, $transformer)) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|             ; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -24,8 +24,8 @@ declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreRequest; | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Api\V2\Request\Model\ExchangeRate\StoreRequest; | ||||
| use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface; | ||||
| use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait; | ||||
| use FireflyIII\Transformers\V2\ExchangeRateTransformer; | ||||
|   | ||||
| @@ -24,8 +24,8 @@ declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\UpdateRequest; | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Api\V2\Request\Model\ExchangeRate\UpdateRequest; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface; | ||||
| use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait; | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| 
 | ||||
| /* | ||||
|  * DestroyRequest.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org. | ||||
|  * Copyright (c) 2025 james@firefly-iii.org. | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
| @@ -22,7 +22,7 @@ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V2\Request\Model\ExchangeRate; | ||||
| namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Support\Request\ChecksLogin; | ||||
| @@ -34,7 +34,7 @@ class DestroyRequest extends FormRequest | ||||
|     use ChecksLogin; | ||||
|     use ConvertsDataTypes; | ||||
| 
 | ||||
|     public function getDate(): Carbon | ||||
|     public function getDate(): ?Carbon | ||||
|     { | ||||
|         return $this->getCarbonDate('date'); | ||||
|     } | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * DestroyRequest.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org. | ||||
|  * StoreRequest.php | ||||
|  * Copyright (c) 2025 james@firefly-iii.org. | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
| @@ -22,7 +22,7 @@ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V2\Request\Model\ExchangeRate; | ||||
| namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * DestroyRequest.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org. | ||||
|  * UpdateRequest.php | ||||
|  * Copyright (c) 2025 james@firefly-iii.org. | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
| @@ -22,7 +22,7 @@ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Api\V2\Request\Model\ExchangeRate; | ||||
| namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Support\Request\ChecksLogin; | ||||
| @@ -30,6 +30,7 @@ use Carbon\Exceptions\InvalidFormatException; | ||||
| use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Support\Facades\Steam; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| 
 | ||||
| /** | ||||
|  * Trait ConvertsDataTypes | ||||
| @@ -359,10 +360,12 @@ trait ConvertsDataTypes | ||||
|     { | ||||
|         $result = null; | ||||
| 
 | ||||
|         Log::debug(sprintf('Date string is "%s"', (string) $this->get($field))); | ||||
|         try { | ||||
|             $result = '' !== (string) $this->get($field) ? new Carbon((string) $this->get($field), config('app.timezone')) : null; | ||||
|         } catch (InvalidFormatException $e) { | ||||
|             // @ignoreException
 | ||||
|             Log::debug(sprintf('Exception when parsing date "%s".', $this->get($field))); | ||||
|         } | ||||
|         if (null === $result) { | ||||
|             app('log')->debug(sprintf('Exception when parsing date "%s".', $this->get($field))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user