feat(transaction): #80 add errors to transactions
This commit was merged in pull request #84.
This commit is contained in:
@@ -3,12 +3,14 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
"spend-sparrow/handler/middleware"
|
||||
"spend-sparrow/log"
|
||||
"spend-sparrow/service"
|
||||
t "spend-sparrow/template/transaction"
|
||||
"spend-sparrow/types"
|
||||
"spend-sparrow/utils"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Transaction interface {
|
||||
@@ -85,7 +87,9 @@ func (h TransactionImpl) handleTransactionPage() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
comp := t.Transaction(transactions, accounts, treasureChests)
|
||||
accountMap, treasureChestMap := h.getTransactionData(accounts, treasureChests)
|
||||
|
||||
comp := t.Transaction(transactions, accountMap, treasureChestMap)
|
||||
h.r.RenderLayout(r, w, comp, user)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +131,8 @@ func (h TransactionImpl) handleTransactionItemComp() http.HandlerFunc {
|
||||
if r.URL.Query().Get("edit") == "true" {
|
||||
comp = t.EditTransaction(transaction, accounts, treasureChests)
|
||||
} else {
|
||||
comp = t.TransactionItem(transaction)
|
||||
accountMap, treasureChestMap := h.getTransactionData(accounts, treasureChests)
|
||||
comp = t.TransactionItem(transaction, accountMap, treasureChestMap)
|
||||
}
|
||||
h.r.Render(r, w, comp)
|
||||
}
|
||||
@@ -169,7 +174,20 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
comp := t.TransactionItem(transaction)
|
||||
accounts, err := h.account.GetAll(user)
|
||||
if err != nil {
|
||||
handleError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
treasureChests, err := h.treasureChest.GetAll(user)
|
||||
if err != nil {
|
||||
handleError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
accountMap, treasureChestMap := h.getTransactionData(accounts, treasureChests)
|
||||
comp := t.TransactionItem(transaction, accountMap, treasureChestMap)
|
||||
h.r.Render(r, w, comp)
|
||||
}
|
||||
}
|
||||
@@ -191,3 +209,22 @@ func (h TransactionImpl) handleDeleteTransaction() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h TransactionImpl) getTransactionData(accounts []*types.Account, treasureChests []*types.TreasureChest) (map[uuid.UUID]string, map[uuid.UUID]string) {
|
||||
accountMap := make(map[uuid.UUID]string, 0)
|
||||
for _, account := range accounts {
|
||||
accountMap[account.Id] = account.Name
|
||||
}
|
||||
treasureChestMap := make(map[uuid.UUID]string, 0)
|
||||
root := ""
|
||||
for _, treasureChest := range treasureChests {
|
||||
if treasureChest.ParentId == uuid.Nil {
|
||||
root = treasureChest.Name + " > "
|
||||
treasureChestMap[treasureChest.Id] = treasureChest.Name
|
||||
} else {
|
||||
treasureChestMap[treasureChest.Id] = root + treasureChest.Name
|
||||
}
|
||||
}
|
||||
log.Info("treasureChestMap: %v", treasureChestMap)
|
||||
return accountMap, treasureChestMap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user