feat(transaction): #66 implement transactions
This commit is contained in:
@@ -16,16 +16,20 @@ type Transaction interface {
|
||||
}
|
||||
|
||||
type TransactionImpl struct {
|
||||
s service.Transaction
|
||||
a service.Auth
|
||||
r *Render
|
||||
s service.Transaction
|
||||
account service.Account
|
||||
treasureChest service.TreasureChest
|
||||
a service.Auth
|
||||
r *Render
|
||||
}
|
||||
|
||||
func NewTransaction(s service.Transaction, a service.Auth, r *Render) Transaction {
|
||||
func NewTransaction(s service.Transaction, account service.Account, treasureChest service.TreasureChest, a service.Auth, r *Render) Transaction {
|
||||
return TransactionImpl{
|
||||
s: s,
|
||||
a: a,
|
||||
r: r,
|
||||
s: s,
|
||||
account: account,
|
||||
treasureChest: treasureChest,
|
||||
a: a,
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +54,19 @@ func (h TransactionImpl) handleTransactionPage() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
comp := t.Transaction(transactions)
|
||||
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
|
||||
}
|
||||
|
||||
comp := t.Transaction(transactions, accounts, treasureChests)
|
||||
h.r.RenderLayout(r, w, comp, user)
|
||||
}
|
||||
}
|
||||
@@ -63,9 +79,21 @@ func (h TransactionImpl) handleTransactionItemComp() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
id := r.PathValue("id")
|
||||
if id == "new" {
|
||||
comp := t.EditTransaction(nil)
|
||||
comp := t.EditTransaction(nil, accounts, treasureChests)
|
||||
h.r.Render(r, w, comp)
|
||||
return
|
||||
}
|
||||
@@ -78,7 +106,7 @@ func (h TransactionImpl) handleTransactionItemComp() http.HandlerFunc {
|
||||
|
||||
var comp templ.Component
|
||||
if r.URL.Query().Get("edit") == "true" {
|
||||
comp = t.EditTransaction(transaction)
|
||||
comp = t.EditTransaction(transaction, accounts, treasureChests)
|
||||
} else {
|
||||
comp = t.TransactionItem(transaction)
|
||||
}
|
||||
@@ -98,16 +126,23 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
|
||||
transaction *types.Transaction
|
||||
err error
|
||||
)
|
||||
id := r.PathValue("id")
|
||||
name := r.FormValue("name")
|
||||
if id == "new" {
|
||||
transaction, err = h.s.Add(user, name)
|
||||
input := types.TransactionInput{
|
||||
Id: r.PathValue("id"),
|
||||
AccountId: r.FormValue("account_id"),
|
||||
TreasureChestId: r.FormValue("treasure_chest_id"),
|
||||
Value: r.FormValue("value"),
|
||||
Timestamp: r.FormValue("timestamp"),
|
||||
Note: r.FormValue("note"),
|
||||
}
|
||||
|
||||
if input.Id == "new" {
|
||||
transaction, err = h.s.Add(user, input)
|
||||
if err != nil {
|
||||
handleError(w, r, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
transaction, err = h.s.Update(user, id, name)
|
||||
transaction, err = h.s.Update(user, input)
|
||||
if err != nil {
|
||||
handleError(w, r, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user