Skip to content

Commit

Permalink
Merge pull request #451 from range-of-motion/show-tags-whilst-creatin…
Browse files Browse the repository at this point in the history
…g-spending-in-spa-prototype

Show tags whilst creating spending in SPA prototype
  • Loading branch information
range-of-motion authored Dec 3, 2023
2 parents 0806656 + c244224 commit 0f51dcb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/Api/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\TagResource;
use Illuminate\Http\Request;

class TagController extends Controller
{
public function index(Request $request)
{
/** @var ApiKey $apiKey */
$apiKey = $request->get('apiKey');

return TagResource::collection($apiKey->user->spaces()->first()->tags);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function store(Request $request)

$request->validate([
'type' => ['required', 'in:earning,spending'],
// 'tag_id' => ['nullable', 'exists:tags,id'], // TODO CHECK IF TAG BELONGS TO USER
'tag_id' => ['nullable', 'exists:tags,id'], // TODO: CHECK IF TAG BELONGS TO USER
'happened_on' => ['required', 'date', 'date_format:Y-m-d'],
'description' => ['required', 'max:255'],
'amount' => ['required', 'regex:/^\d*(\.\d{1,2})?$/'],
Expand All @@ -58,7 +58,7 @@ public function store(Request $request)
'space_id' => $spaceId,
'import_id' => null, // TODO
'recurring_id' => null, // TODO
'tag_id' => null, // TODO
'tag_id' => $request->input('tag_id'),
'happened_on' => $request->input('happened_on'),
'description' => $request->input('description'),
'amount' => (int) ($request->input('amount') * 100),
Expand Down
19 changes: 18 additions & 1 deletion resources/assets/js/prototype/screens/Transactions/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ import Navigation from '../../components/Navigation.vue';
const router = getCurrentInstance().proxy.$router;
const tags = ref([]);
const type = ref('earning');
const tagId = ref(null);
const happened_on = ref(new Date().toJSON().slice(0, 10));
const description = ref('');
const amount = ref(10.00);
const fetchTags = () => {
fetch('/api/tags', { headers: { 'api-key': localStorage.getItem('api_key') } })
.then(response => response.json())
.then(data => {
tags.value = data;
});
};
const create = () => {
axios.post('/api/transactions', {
type: type.value,
tag_id: tagId.value,
happened_on: happened_on.value,
description: description.value,
amount: amount.value,
Expand All @@ -29,6 +41,8 @@ const create = () => {
alert('Something went wrong');
});
};
fetchTags();
</script>

<template>
Expand All @@ -42,7 +56,10 @@ const create = () => {
</div>
<div v-if="type === 'spending'">
<label class="mb-2 block text-sm dark:text-white">Tag</label>
<input class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg" type="text" value="Coming soon" disabled />
<select class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg appearance-none" v-model="tagId">
<option :value="null">-</option>
<option v-for="tag in tags" :key="tag.id" :value="tag.id">{{ tag.name }}</option>
</select>
</div>
<div>
<label class="mb-2 block text-sm dark:text-white">Date</label>
Expand Down
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use App\Http\Controllers\Api\LogInController;
use App\Http\Controllers\Api\SettingsController;
use App\Http\Controllers\Api\TagController;
use App\Http\Controllers\Api\TransactionController;
use Illuminate\Support\Facades\Route;

Expand All @@ -12,6 +13,9 @@
Route::resource('transactions', TransactionController::class)
->only(['index', 'store']);

Route::resource('tags', TagController::class)
->only(['index']);

Route::resource('settings', SettingsController::class)
->only(['index', 'store']);
});

0 comments on commit 0f51dcb

Please sign in to comment.