diff --git a/app/Http/Controllers/Api/TransactionController.php b/app/Http/Controllers/Api/TransactionController.php
index e57113f0..31b9c21c 100644
--- a/app/Http/Controllers/Api/TransactionController.php
+++ b/app/Http/Controllers/Api/TransactionController.php
@@ -33,4 +33,46 @@ public function index(Request $request)
return TransactionResource::collection($transactions);
}
+
+ public function store(Request $request)
+ {
+ $apiKey = ApiKey::query()
+ ->where('token', $request->header('api-key'))
+ ->first();
+
+ if (!$apiKey) {
+ abort(401);
+ }
+
+ $spaceId = $apiKey->user->spaces()->first()->id;
+
+ $request->validate([
+ 'type' => 'in:earning,spending',
+ // TODO
+ ]);
+
+ if ($request->input('type') === 'earning') {
+ Earning::create([
+ 'space_id' => $spaceId,
+ 'recurring_id' => null, // TODO
+ 'happened_on' => $request->input('happened_on'),
+ 'description' => $request->input('description'),
+ 'amount' => $request->input('amount')
+ ]);
+ }
+
+ if ($request->input('type') === 'spending') {
+ Spending::create([
+ 'space_id' => $spaceId,
+ 'import_id' => null, // TODO
+ 'recurring_id' => null, // TODO
+ 'tag_id' => null, // TODO
+ 'happened_on' => $request->input('happened_on'),
+ 'description' => $request->input('description'),
+ 'amount' => $request->input('amount')
+ ]);
+ }
+
+ return [];
+ }
}
diff --git a/resources/assets/js/prototype/app.js b/resources/assets/js/prototype/app.js
index 29af9bc3..21979604 100644
--- a/resources/assets/js/prototype/app.js
+++ b/resources/assets/js/prototype/app.js
@@ -6,6 +6,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';
+import TransactionsCreate from './screens/Transactions/Create.vue';
Vue.use(VueRouter);
@@ -22,6 +23,10 @@ const routes = [
path: '/prototype/transactions',
name: 'transactions.index',
component: TransactionsIndex,
+ }, {
+ path: '/prototype/transactions/create',
+ name: 'transactions.create',
+ component: TransactionsCreate,
},
];
diff --git a/resources/assets/js/prototype/screens/Transactions/Create.vue b/resources/assets/js/prototype/screens/Transactions/Create.vue
new file mode 100644
index 00000000..cf64cfc7
--- /dev/null
+++ b/resources/assets/js/prototype/screens/Transactions/Create.vue
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/routes/api.php b/routes/api.php
index 1ab5db4f..7c369b50 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -7,3 +7,4 @@
Route::post('/log-in', LogInController::class);
Route::get('/transactions', [TransactionController::class, 'index']);
+Route::post('/transactions', [TransactionController::class, 'store']);
diff --git a/routes/web.php b/routes/web.php
index 1c1893cc..14aec035 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -135,5 +135,5 @@
Route::prefix('prototype')
->group(function () {
Route::get('/', fn () => 'Hello world');
- Route::get('/{any}', \App\Http\Controllers\PrototypeController::class);
+ Route::get('/{any}', \App\Http\Controllers\PrototypeController::class)->where('any', '.*');
});