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