From 6647c656900a13865cacd76b05388cec777815b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Wed, 25 Oct 2023 14:22:32 +0200 Subject: [PATCH] Create endpoint for fetching transactions --- .../Controllers/Api/TransactionController.php | 26 ++++++ app/Http/Resources/TransactionResource.php | 23 +++++ app/Providers/AppServiceProvider.php | 3 + resources/assets/js/prototype/app.js | 5 ++ .../js/prototype/components/Navigation.vue | 14 +++ .../assets/js/prototype/screens/Dashboard.vue | 3 +- .../prototype/screens/Transactions/Index.vue | 89 +++++++++++++++++++ routes/api.php | 3 + 8 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Api/TransactionController.php create mode 100644 app/Http/Resources/TransactionResource.php create mode 100644 resources/assets/js/prototype/components/Navigation.vue create mode 100644 resources/assets/js/prototype/screens/Transactions/Index.vue diff --git a/app/Http/Controllers/Api/TransactionController.php b/app/Http/Controllers/Api/TransactionController.php new file mode 100644 index 00000000..9767316f --- /dev/null +++ b/app/Http/Controllers/Api/TransactionController.php @@ -0,0 +1,26 @@ +push($earning); + } + + foreach (Spending::all() as $spending) { + $transactions->push($spending); + } + + return TransactionResource::collection($transactions); + } +} diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php new file mode 100644 index 00000000..680ecd92 --- /dev/null +++ b/app/Http/Resources/TransactionResource.php @@ -0,0 +1,23 @@ +resource) === Earning::class; + + return [ + 'id' => $this->id, + 'type' => $isEarning ? 'earning' : 'spending', + 'happened_on' => $this->happened_on, + 'description' => $this->description, + 'amount' => $this->amount, + ]; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 726b41ec..69a3a4f2 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ use App\Helper; use App\Models\Space; +use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\ServiceProvider; use Auth; @@ -11,6 +12,8 @@ class AppServiceProvider extends ServiceProvider { public function boot() { + JsonResource::withoutWrapping(); + view()->composer('*', function ($view) { $selectedSpace = session('space_id') ? Space::find(session('space_id')) : null; diff --git a/resources/assets/js/prototype/app.js b/resources/assets/js/prototype/app.js index f2e982e8..29af9bc3 100644 --- a/resources/assets/js/prototype/app.js +++ b/resources/assets/js/prototype/app.js @@ -5,6 +5,7 @@ import App from './components/App.vue'; import Login from './screens/Login.vue'; import Dashboard from './screens/Dashboard.vue'; +import TransactionsIndex from './screens/Transactions/Index.vue'; Vue.use(VueRouter); @@ -17,6 +18,10 @@ const routes = [ path: '/prototype/dashboard', name: 'dashboard', component: Dashboard, + }, { + path: '/prototype/transactions', + name: 'transactions.index', + component: TransactionsIndex, }, ]; diff --git a/resources/assets/js/prototype/components/Navigation.vue b/resources/assets/js/prototype/components/Navigation.vue new file mode 100644 index 00000000..a9033b51 --- /dev/null +++ b/resources/assets/js/prototype/components/Navigation.vue @@ -0,0 +1,14 @@ + + + diff --git a/resources/assets/js/prototype/screens/Dashboard.vue b/resources/assets/js/prototype/screens/Dashboard.vue index 4c14c6f3..c45169bc 100644 --- a/resources/assets/js/prototype/screens/Dashboard.vue +++ b/resources/assets/js/prototype/screens/Dashboard.vue @@ -1,9 +1,10 @@