mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Fix routes
This commit is contained in:
@@ -39,6 +39,8 @@ class ShowController extends Controller
|
||||
public function show(Account $account): JsonResponse
|
||||
{
|
||||
$transformer = new AccountTransformer;
|
||||
return response()->json($this->jsonApiObject('accounts', $account, $transformer));
|
||||
return response()
|
||||
->api($this->jsonApiObject('accounts', $account, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ class NetWorthController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
@@ -52,13 +53,17 @@ class NetWorthController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SingleDateRequest $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function get(SingleDateRequest $request): JsonResponse
|
||||
{
|
||||
$date = $request->getDate();
|
||||
$result = $this->netWorth->sumNetWorthByCurrency($date);
|
||||
$converted = $this->cerSum($result);
|
||||
|
||||
return response()->json($converted);
|
||||
return response()->api($converted);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ class SingleDateRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'required|date',
|
||||
'date' => 'required|date|after:1900-01-01|before:2099-12-31',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@
|
||||
namespace FireflyIII\Transformers\V2;
|
||||
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
|
||||
/**
|
||||
* Class TransactionGroupTransformer
|
||||
@@ -35,7 +36,6 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(array $group): array
|
||||
{
|
||||
//$data = new NullArrayObject($group);
|
||||
$first = reset($group['transactions']);
|
||||
|
||||
return [
|
||||
@@ -48,7 +48,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/transactions/' . 1,
|
||||
'uri' => sprintf('/transactions/%d', $group['id']),
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -70,13 +70,12 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
|
||||
private function transformTransaction(array $transaction): array
|
||||
{
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
|
||||
// amount:
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
$amount = app('steam')->positive((string) ($row['amount'] ?? '0'));
|
||||
$foreignAmount = null;
|
||||
if (null !== $row['foreign_amount']) {
|
||||
$foreignAmount = app('steam')->positive($row['foreign_amount']);
|
||||
if (null !== $transaction['foreign_amount']) {
|
||||
$foreignAmount = app('steam')->positive($transaction['foreign_amount']);
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -154,23 +153,23 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
/**
|
||||
* TODO also in the old transformer.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param string|null $default
|
||||
* @param NullArrayObject $array
|
||||
* @param string $key
|
||||
* @param string|null $default
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function stringFromArray(array $array, string $key, ?string $default): ?string
|
||||
private function stringFromArray(NullArrayObject $array, string $key, ?string $default): ?string
|
||||
{
|
||||
if (array_key_exists($key, $array) && null === $array[$key]) {
|
||||
if (null === $array[$key] && null === $default) {
|
||||
return null;
|
||||
}
|
||||
if (array_key_exists($key, $array) && null !== $array[$key]) {
|
||||
if (null !== $array[$key]) {
|
||||
return (string) $array[$key];
|
||||
}
|
||||
|
||||
if (null !== $default) {
|
||||
return (string) $default;
|
||||
return $default;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -26,13 +26,13 @@ declare(strict_types=1);
|
||||
* V2 API route for TransactionSum API endpoints
|
||||
* TODO what to do with these routes
|
||||
*/
|
||||
Route::group(
|
||||
['namespace' => 'FireflyIII\Api\V2\Controllers\Transaction\Sum', 'prefix' => 'v2/transaction/sum',
|
||||
'as' => 'api.v2.transaction.sum.',],
|
||||
static function () {
|
||||
Route::get('bills/paid', ['uses' => 'BillController@paid', 'as' => 'bills.paid']);
|
||||
}
|
||||
);
|
||||
//Route::group(
|
||||
// ['namespace' => 'FireflyIII\Api\V2\Controllers\Transaction\Sum', 'prefix' => 'v2/transaction/sum',
|
||||
// 'as' => 'api.v2.transaction.sum.',],
|
||||
// static function () {
|
||||
// Route::get('bills/paid', ['uses' => 'BillController@paid', 'as' => 'bills.paid']);
|
||||
// }
|
||||
//);
|
||||
|
||||
/**
|
||||
* V2 API route for TransactionList API endpoints
|
||||
|
Reference in New Issue
Block a user