Update existing transaction if transactionid was passed
This commit is contained in:
parent
2f4f8a7568
commit
07804e4241
@ -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,9 +86,9 @@ 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 {
|
||||||
newTransaction.GroupID = uuid.NullUUID{UUID: uuid.New(), Valid: true}
|
newTransaction.GroupID = uuid.NullUUID{UUID: uuid.New(), Valid: true}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user