This commit is contained in:
James Cole 2020-03-20 04:42:19 +01:00
parent 7eb2451e3d
commit 9e54ebe6a9
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 104 additions and 70 deletions

View File

@ -567,6 +567,26 @@ class CurrencyController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* Show a currency.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function showDefault(): JsonResponse
{
$manager = $this->getManager();
$currency = app('amount')->getDefaultCurrencyByUser(auth()->user());
/** @var CurrencyTransformer $transformer */
$transformer = app(CurrencyTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* Store new currency.
*

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* api.php
@ -20,7 +21,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
use FireflyIII\Http\Middleware\IsAdmin;
Route::group(
[
@ -48,6 +50,7 @@ Route::group(
Route::get('{account}/piggy_banks', ['uses' => 'AccountController@piggyBanks', 'as' => 'piggy_banks']);
Route::get('{account}/transactions', ['uses' => 'AccountController@transactions', 'as' => 'transactions']);
Route::get('{account}/attachments', ['uses' => 'AccountController@attachments', 'as' => 'attachments']);
}
);
@ -83,7 +86,8 @@ Route::group(
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'bills',
'as' => 'api.v1.bills.', ], static function () {
'as' => 'api.v1.bills.',],
static function () {
// Bills API routes:
Route::get('', ['uses' => 'BillController@index', 'as' => 'index']);
@ -109,6 +113,7 @@ Route::group(
Route::get('{budgetLimit}', ['uses' => 'BudgetLimitController@show', 'as' => 'show']);
Route::put('{budgetLimit}', ['uses' => 'BudgetLimitController@update', 'as' => 'update']);
Route::delete('{budgetLimit}', ['uses' => 'BudgetLimitController@delete', 'as' => 'delete']);
Route::get('{budgetLimit}/transactions', ['uses' => 'BudgetLimitController@transactions', 'as' => 'transactions']);
}
);
@ -124,9 +129,11 @@ Route::group(
Route::get('{budget}', ['uses' => 'BudgetController@show', 'as' => 'show']);
Route::put('{budget}', ['uses' => 'BudgetController@update', 'as' => 'update']);
Route::delete('{budget}', ['uses' => 'BudgetController@delete', 'as' => 'delete']);
Route::get('{budget}/transactions', ['uses' => 'BudgetController@transactions', 'as' => 'transactions']);
Route::get('{budget}/limits', ['uses' => 'BudgetController@budgetLimits', 'as' => 'budget_limits']);
Route::post('{budget}/limits', ['uses' => 'BudgetController@storeBudgetLimit', 'as' => 'store_budget_limit']);
Route::get('{budget}/transactions', ['uses' => 'BudgetController@transactions', 'as' => 'transactions']);
Route::get('{budget}/attachments', ['uses' => 'BudgetController@attachments', 'as' => 'attachments']);
Route::get('{budget}/limits', ['uses' => 'BudgetController@budgetLimits', 'as' => 'budget_limits']);
}
);
@ -141,7 +148,9 @@ Route::group(
Route::get('{category}', ['uses' => 'CategoryController@show', 'as' => 'show']);
Route::put('{category}', ['uses' => 'CategoryController@update', 'as' => 'update']);
Route::delete('{category}', ['uses' => 'CategoryController@delete', 'as' => 'delete']);
Route::get('{category}/transactions', ['uses' => 'CategoryController@transactions', 'as' => 'transactions']);
Route::get('{category}/attachments', ['uses' => 'CategoryController@attachments', 'as' => 'attachments']);
}
);
@ -252,9 +261,11 @@ Route::group(
Route::get('', ['uses' => 'PiggyBankController@index', 'as' => 'index']);
Route::post('', ['uses' => 'PiggyBankController@store', 'as' => 'store']);
Route::get('{piggyBank}', ['uses' => 'PiggyBankController@show', 'as' => 'show']);
Route::get('{piggyBank}/events', ['uses' => 'PiggyBankController@piggyBankEvents', 'as' => 'events']);
Route::put('{piggyBank}', ['uses' => 'PiggyBankController@update', 'as' => 'update']);
Route::delete('{piggyBank}', ['uses' => 'PiggyBankController@delete', 'as' => 'delete']);
Route::get('{piggyBank}/events', ['uses' => 'PiggyBankController@piggyBankEvents', 'as' => 'events']);
Route::get('{piggyBank}/attachments', ['uses' => 'PiggyBankController@attachments', 'as' => 'attachments']);
}
);
@ -354,6 +365,7 @@ Route::group(
// Transaction currency API routes:
Route::get('', ['uses' => 'CurrencyController@index', 'as' => 'index']);
Route::post('', ['uses' => 'CurrencyController@store', 'as' => 'store']);
Route::get('default', ['uses' => 'CurrencyController@showDefault', 'as' => 'show.default']);
Route::get('{currency_code}', ['uses' => 'CurrencyController@show', 'as' => 'show']);
Route::put('{currency_code}', ['uses' => 'CurrencyController@update', 'as' => 'update']);
Route::delete('{currency_code}', ['uses' => 'CurrencyController@delete', 'as' => 'delete']);
@ -383,7 +395,9 @@ Route::group(
Route::get('{tagOrId}', ['uses' => 'TagController@show', 'as' => 'show']);
Route::put('{tagOrId}', ['uses' => 'TagController@update', 'as' => 'update']);
Route::delete('{tagOrId}', ['uses' => 'TagController@delete', 'as' => 'delete']);
Route::get('{tagOrId}/transactions', ['uses' => 'TagController@transactions', 'as' => 'transactions']);
Route::get('{tagOrId}/attachments', ['uses' => 'TagController@attachments', 'as' => 'attachments']);
}
);
@ -425,7 +439,7 @@ Route::group(
);
Route::group(
['middleware' => ['auth:api', 'bindings', \FireflyIII\Http\Middleware\IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'users',
['middleware' => ['auth:api', 'bindings', IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'users',
'as' => 'api.v1.users.',],
static function () {