Implement editing of transactions #23

Merged
jacob1123 merged 22 commits from edit-transaction into master 2022-02-25 23:35:12 +01:00
Showing only changes of commit 07804e4241 - Show all commits

View File

@ -41,6 +41,23 @@ func (h *Handler) newTransaction(c *gin.Context) {
return return
} }
transactionID := c.Param("transactionid")
if transactionID != "" {
editTransaction := postgres.UpdateTransactionParams{
Memo: payload.Memo,
Date: time.Time(payload.Date),
Amount: amount,
PayeeID: payload.Payee.ID,
CategoryID: payload.CategoryID,
ID: uuid.MustParse(transactionID),
}
err := h.Service.UpdateTransaction(c.Request.Context(), editTransaction)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("edit transaction: %w", err))
return
}
} else {
newTransaction := postgres.CreateTransactionParams{ newTransaction := postgres.CreateTransactionParams{
Memo: payload.Memo, Memo: payload.Memo,
Date: time.Time(payload.Date), Date: time.Time(payload.Date),
@ -69,8 +86,8 @@ func (h *Handler) newTransaction(c *gin.Context) {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err)) c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
return return
} }
c.JSON(http.StatusOK, transaction) c.JSON(http.StatusOK, transaction)
}
} }
func (h *Handler) CreateTransferForOtherAccount(newTransaction postgres.CreateTransactionParams, amount numeric.Numeric, payload NewTransactionPayload, err error, c *gin.Context) error { func (h *Handler) CreateTransferForOtherAccount(newTransaction postgres.CreateTransactionParams, amount numeric.Numeric, payload NewTransactionPayload, err error, c *gin.Context) error {