From 953d348bed2371feabfb8ea0b13a686054772352 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 15 Feb 2022 09:02:01 +0000 Subject: [PATCH 1/3] Handle new Payees --- server/transaction.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/server/transaction.go b/server/transaction.go index 072f8ad..3a7bf9a 100644 --- a/server/transaction.go +++ b/server/transaction.go @@ -35,8 +35,6 @@ func (h *Handler) newTransaction(c *gin.Context) { return } - fmt.Printf("%v\n", payload) - amount := postgres.Numeric{} err = amount.Set(payload.Amount) if err != nil { @@ -44,12 +42,29 @@ func (h *Handler) newTransaction(c *gin.Context) { return } + payeeID := payload.Payee.ID + if !payeeID.Valid && payload.Payee.Name != "" { + newPayee := postgres.CreatePayeeParams{ + Name: payload.Payee.Name, + BudgetID: payload.BudgetID, + } + payee, err := h.Service.CreatePayee(c.Request.Context(), newPayee) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err)) + } + + payeeID = uuid.NullUUID{ + UUID: payee.ID, + Valid: true, + } + } + newTransaction := postgres.CreateTransactionParams{ Memo: payload.Memo, Date: time.Time(payload.Date), Amount: amount, AccountID: payload.AccountID, - PayeeID: payload.Payee.ID, + PayeeID: payeeID, CategoryID: payload.Category.ID, Status: postgres.TransactionStatus(payload.State), } -- 2.47.2 From 73e3b49b40284e0a8b3129b6cca792cc506eae2b Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 15 Feb 2022 09:02:14 +0000 Subject: [PATCH 2/3] Extract component for new Transaction --- web/src/components/TransactionInputRow.vue | 59 ++++++++++++++++++++++ web/src/pages/Account.vue | 49 +----------------- 2 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 web/src/components/TransactionInputRow.vue diff --git a/web/src/components/TransactionInputRow.vue b/web/src/components/TransactionInputRow.vue new file mode 100644 index 0000000..1724dc3 --- /dev/null +++ b/web/src/components/TransactionInputRow.vue @@ -0,0 +1,59 @@ + + + \ No newline at end of file diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index dcc7905..d38b6b1 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -3,7 +3,7 @@ import { computed, ref } from "vue" import Autocomplete, { Suggestion } from '../components/Autocomplete.vue' import Currency from "../components/Currency.vue"; import TransactionRow from "../components/TransactionRow.vue"; -import { POST } from "../api"; +import TransactionInputRow from "../components/TransactionInputRow.vue"; import { useAccountStore } from "../stores/budget-account"; const props = defineProps<{ @@ -11,27 +11,6 @@ const props = defineProps<{ accountid: string }>() -const TransactionDate = ref(new Date().toISOString().substring(0, 10)); -const Payee = ref(undefined); -const Category = ref(undefined); -const Memo = ref(""); -const Amount = ref(0); - -function saveTransaction(e: MouseEvent) { - e.preventDefault(); - POST("/transaction/new", JSON.stringify({ - budget_id: props.budgetid, - account_id: props.accountid, - date: TransactionDate.value, - payee: Payee.value, - category: Category.value, - memo: Memo.value, - amount: Amount, - state: "Uncleared" - })) - .then(x => x.json()); -} - const accountStore = useAccountStore(); const CurrentAccount = computed(() => accountStore.CurrentAccount); const TransactionsList = computed(() => accountStore.TransactionsList); @@ -53,31 +32,7 @@ const TransactionsList = computed(() => accountStore.TransactionsList); - - - - - - - - - - - - - - - - - - - - - + Date: Tue, 15 Feb 2022 09:13:14 +0000 Subject: [PATCH 3/3] Add Transaction to list after saving --- server/transaction.go | 5 +++- web/src/components/TransactionInputRow.vue | 30 ++++++++++++---------- web/src/pages/Account.vue | 1 - web/src/stores/budget-account.ts | 15 +++++++---- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/server/transaction.go b/server/transaction.go index 3a7bf9a..05b0595 100644 --- a/server/transaction.go +++ b/server/transaction.go @@ -68,8 +68,11 @@ func (h *Handler) newTransaction(c *gin.Context) { CategoryID: payload.Category.ID, Status: postgres.TransactionStatus(payload.State), } - _, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction) + transaction, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction) if err != nil { c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err)) + return } + + c.JSON(http.StatusOK, transaction) } diff --git a/web/src/components/TransactionInputRow.vue b/web/src/components/TransactionInputRow.vue index 1724dc3..d493689 100644 --- a/web/src/components/TransactionInputRow.vue +++ b/web/src/components/TransactionInputRow.vue @@ -1,7 +1,7 @@ diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index d38b6b1..af169bf 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -1,6 +1,5 @@