Use JSON params instead of PostForm
This commit is contained in:
parent
d5904a7c4a
commit
3d1d1308ac
@ -59,48 +59,16 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
||||
}
|
||||
|
||||
fmt.Printf("%v\n", payload)
|
||||
/* c.JSON(http.StatusOK, payload)*/
|
||||
return
|
||||
|
||||
transactionMemo, _ := c.GetPostForm("memo")
|
||||
transactionAccountID, err := getUUID(c, "account_id")
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("account_id: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
transactionCategoryID, err := getNullUUIDFromForm(c, "category_id")
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("category_id: %w", err))
|
||||
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"))
|
||||
return
|
||||
}
|
||||
|
||||
transactionDateValue, err := time.Parse("2006-01-02", transactionDate)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("date is not a valid date"))
|
||||
return
|
||||
}
|
||||
|
||||
transactionAmount, succ := c.GetPostForm("amount")
|
||||
if !succ {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("amount missing"))
|
||||
return
|
||||
}
|
||||
|
||||
amount := postgres.Numeric{}
|
||||
amount.Set(transactionAmount)
|
||||
amount.Set(payload.Amount)
|
||||
|
||||
transactionUUID, err := getNullUUIDFromParam(c, "transactionid")
|
||||
if err != nil {
|
||||
@ -110,12 +78,12 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
||||
|
||||
if !transactionUUID.Valid {
|
||||
new := postgres.CreateTransactionParams{
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Memo: payload.Memo,
|
||||
Date: time.Time(payload.Date),
|
||||
Amount: amount,
|
||||
AccountID: transactionAccountID,
|
||||
PayeeID: transactionPayeeID,
|
||||
CategoryID: transactionCategoryID,
|
||||
PayeeID: payload.Payee.ID, //TODO handle new payee
|
||||
CategoryID: payload.Category.ID, //TODO handle new category
|
||||
}
|
||||
_, err = h.Service.CreateTransaction(c.Request.Context(), new)
|
||||
if err != nil {
|
||||
@ -136,12 +104,12 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
||||
|
||||
update := postgres.UpdateTransactionParams{
|
||||
ID: transactionUUID.UUID,
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Memo: payload.Memo,
|
||||
Date: time.Time(payload.Date),
|
||||
Amount: amount,
|
||||
AccountID: transactionAccountID,
|
||||
PayeeID: transactionPayeeID,
|
||||
CategoryID: transactionCategoryID,
|
||||
PayeeID: payload.Payee.ID, //TODO handle new payee
|
||||
CategoryID: payload.Category.ID, //TODO handle new category
|
||||
}
|
||||
err = h.Service.UpdateTransaction(c.Request.Context(), update)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user