Add ability to edit payees
This commit is contained in:
@ -72,6 +72,12 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
transactionPayeeID, err := getNullUUIDFromForm(c, "payee_id")
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("payee_id: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
transactionDate, succ := c.GetPostForm("date")
|
||||
if !succ {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("date missing"))
|
||||
@ -95,39 +101,47 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
||||
|
||||
transactionUUID, err := getNullUUIDFromParam(c, "transactionid")
|
||||
if err != nil {
|
||||
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("parse transaction id: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
if !transactionUUID.Valid {
|
||||
new := postgres.CreateTransactionParams{
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Amount: amount,
|
||||
AccountID: transactionAccountID,
|
||||
PayeeID: uuid.NullUUID{},
|
||||
PayeeID: transactionPayeeID,
|
||||
CategoryID: transactionCategoryID,
|
||||
}
|
||||
_, err = h.Service.CreateTransaction(c.Request.Context(), new)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, delete := c.GetPostForm("delete")
|
||||
if delete {
|
||||
h.Service.DeleteTransaction(c.Request.Context(), transactionUUID.UUID)
|
||||
}
|
||||
update := postgres.UpdateTransactionParams{
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Amount: amount,
|
||||
AccountID: transactionAccountID,
|
||||
PayeeID: uuid.NullUUID{},
|
||||
CategoryID: transactionCategoryID,
|
||||
}
|
||||
err = h.Service.UpdateTransaction(c.Request.Context(), update)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
_, delete := c.GetPostForm("delete")
|
||||
if delete {
|
||||
err = h.Service.DeleteTransaction(c.Request.Context(), transactionUUID.UUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
|
||||
return
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("delete transaction: %w", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
update := postgres.UpdateTransactionParams{
|
||||
ID: transactionUUID.UUID,
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Amount: amount,
|
||||
AccountID: transactionAccountID,
|
||||
PayeeID: transactionPayeeID,
|
||||
CategoryID: transactionCategoryID,
|
||||
}
|
||||
err = h.Service.UpdateTransaction(c.Request.Context(), update)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user